当发现 Linux 主机执行缓慢时, 找出占用最多内存及 CPU 资源的 Process, 对于修正问题或对系统进行优化十分有用。
以下指令使用 sort 指令将占用最多系统资源的 process 列出:
# ps -eo pid,ppid,cmd,%mem,%cpu –sort=-%mem | head
执行后会以下面的格式输出:
|
1 2 3 4 5 6 7 8 9 10 |
PID PPID CMD %MEM %CPU 517 32574 /usr/libexec/mysqld --based 10.9 3.5 8639 6688 /usr/sbin/httpd -DFOREGROUN 1.5 1.0 6721 6688 /usr/sbin/httpd -DFOREGROUN 1.5 0.4 6834 6688 /usr/sbin/httpd -DFOREGROUN 1.5 0.4 6742 6688 /usr/sbin/httpd -DFOREGROUN 1.5 0.4 9255 6688 /usr/sbin/httpd -DFOREGROUN 1.4 0.5 6841 6688 /usr/sbin/httpd -DFOREGROUN 1.4 0.4 7530 6688 /usr/sbin/httpd -DFOREGROUN 1.3 0.4 6711 6688 /usr/sbin/httpd -DFOREGROUN 1.3 0.4 |
centos 6 命令行输出
#ps -eo pid,ppid,cmd,%mem -sort=-%mem | head
ERROR: Process ID list syntax error.
因为 wordpress 不能显示两个 “-“, 在 “sort” 前应该是两个 “-“