在帮客户解决问题时客户提出了一项需求,旨在通过shell脚本的方式筛选出Linux系统中cpu占比高的进程,于是做出了如下脚本,经验证,满足客户需要。
#!/bin/bash
while(true);
do sleep 1;
ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head>>cpu.log;
echo "========================================================">>cpu.log;
done