标签:col tail bsp watch 关联数组 sleep 命令 purpose 头部
#!/bin/bash #file name: pcpu_usage.sh #purpose: 计算1小时内进程的CPU占用情况 #SECS为需要进行监视的总秒数 #UNIT_TIME是取样的时间间隔,单位是秒 SECS=3600 UNIT_TIME=60 STEPS=$(( $SECS / $UNIT_TIME )) echo "watching CPU usage..."; for((i=0;i<STEPS;i++)) do ps -eocomm,pcpu | tail -n +2 >> ./cpu_usage.$$ sleep $UNIT_TIME done echo echo CPU eaters: cat ./cpu_usage.$$ | awk ‘ { process[$1]+=$2; } END{ for(i in process) { printf("%-20s %s\n",i,process[i]); } }‘ | sort -nrk 2 | head rm ./cpu_usage.$$
标签:col tail bsp watch 关联数组 sleep 命令 purpose 头部
原文地址:https://www.cnblogs.com/CodePastry/p/13202711.html