Skip to main content

ps 指令

以 PID 查詢

ps -fp <PID>
ps -fp <PID#1>,<PID#2>,<PID#3> 

分析CPU/Memory使用
CPU 使用率最高前10排名

# for CentOS
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head -11

ps aux | head -1; ps aux | sort -rn +2 | head -10
# or
ps aux | head -1; ps aux | sort -rn -k 3 | head -10

Memory 使用率最高前10排名

# for CentOS
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head -11

ps aux | head -1; ps aux | sort -rn +3 | head
# or
ps aux | head -1; ps aux | sort -rn -k 4 | head

ps -eo cmd,pid,ppid,%mem,%cpu --sort=-%mem | head -n 6

ps aux  | awk '{print $6/1024 " MB\t\t" $11}'  | sort -rn | head -25

優先權最高的程序

ps -eakl | sort -n +6 | head
# or
ps -eal | sort -n -k 7 | head

程序以 nice 值排序

ps -eakl | sort -n +7

ps -eal | sort -n -k 8

程序以執行時間排序

ps vx | head -1;ps vx | grep -v PID | sort -rn +3 | head -10

ps vx | head -1;ps vx | grep -v PID | sort -rn -k 4 | head -10

程序以 I/O 排序

ps vx | head -1; ps vx | grep -v PID | sort -rn +4 | head -10

ps vx | head -1; ps vx | grep -v PID | sort -rn -k 5 | head -10

等待中的程序

ps vg | head -1; ps vg | grep -w wait

指定 PID 的啟動時間與總執行時間

ps -p <PID> -o etime,start

每個用戶的程序數量

ps -ef | awk '{print$1}' | sort | uniq -c | sort -nr