linux 记录那些程序占用了过高的cpu 的历史信息记录
把这些记录下来,方便分析用
脚本:
#!/bin/bash while [ 1 = 1 ]; do #计算cpu使用率 cpu=`top -b -n1 | fgrep "Cpu(s)" | tail -1 | awk -F'id,' '{split($1, vs, ","); v=vs[length(vs)]; sub(/\s+/, "", v);sub(/\s+/, "", v); printf "%d", 100-v;}'` #统计内存使用率 #mem_used_persent=`free -m | awk -F '[ :]+' 'NR==2{printf "%d", ($2-$7)/$2*100}'` if [ $cpu -gt 60 ]; then echo "注意CPU负载高 $cpu % $(date)" ps auxw|head -1;ps -auxf|sort -nr -k3|head -10 echo =============Next Loop===============; echo =============Next Loop===============; fi sleep 60; done
然后使用screen 入住后台
参考:
https://blog.csdn.net/qq_43150057/article/details/124950183
https://blog.csdn.net/rao991207823/article/details/123660020