找出CPU占用最高的前10个程序
2020-10-22 本文已影响0人
阿当运维
ps的-o选项就是把让ps格式化输出ps你想要的信息,比如只想输出进程的pid、CPU占用率和进程执行命令这三个信息怎么办,你当然可以ps aux全部输出然后切割输出,但是ps的-o选项可以让你很方便的满足上面的需求
思路:
ps -eo显示pid,cpu占用率,内存占用率,进程,在利用--sort排序取前10个程序
ps -eo pid,pcpu,pmem,args --sort=-pcpu|head -10
ps -eo pid,pcpu,pmem,args --sort=-pmem|head -10
结果
内存占用前10的程序

CPU占用前10的程序

也可以利用ps aux+awk取值
ps aux --sort=-%cpu|awk '{print $2,$3,$4,$NF}'|head -10
内存增序
ps aux --sort rss
内存减序
ps aux --sort -rss
cpu增序
ps auxw --sort=%cpu
cpu减序
ps auxw --sort=-%cpu