當發現 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” 前應該是兩個 “-“