如何查看CPU 占用率

以下是查看CPU占用率的一个脚本

 /export/home/arbsfr/SFR_ENTREPRISE/SFRE3/cpu_record.sh

And you can run it as below :
sh cpu_record.sh <CAP pid>

#!bin/sh

/usr/ucb/ps -auxww | grep '%CPU' | grep -v 'grep'
while [ 1 ]
do
        /usr/ucb/ps -auxww | grep $1 | grep -v 'cpu_record.sh' | grep -v 'grep'
        sleep 10
done

发现他用的是/usr/ucb/ps 而不是我们通常用的ps(/bin/ps).
/usr/ucb这个目录里面放的是Berkley 的命令,属于历史遗留命令.Both /usr/bin/ps and /usr/ucb/ps are hard link to /usr/lib/isaexec, which analyses the path and execute the binary differently. /usr/ucb/ps is Berkley style and /usr/bin/ps is SVR4 style. However, they are the same file.

运行脚本后我们可以查看CPU的占用率如下所示:

USER       PID %CPU %MEM   SZ  RSS TT       S    START  TIME COMMAND
arbsfr    8331  0.2  0.17315263944 pts/32   S 08:23:35  0:06 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.4  0.17724868040 pts/32   O 08:23:35  0:14 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.4  0.1122304113096 pts/32   O 08:23:35  0:19 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.5  0.1155072145864 pts/32   O 08:23:35  0:27 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.5  0.2167360158152 pts/32   O 08:23:35  0:35 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.6  0.2179648170440 pts/32   O 08:23:35  0:42 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.6  0.2224704215496 pts/32   O 08:23:35  0:50 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.6  0.2269760260552 pts/32   O 08:23:35  0:58 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.6  0.3306624297416 pts/32   O 08:23:35  1:06 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.6  0.3359872350664 pts/32   O 08:23:35  1:13 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.6  0.3404928395872 pts/32   O 08:23:35  1:19 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.6  0.3404928395872 pts/32   O 08:23:35  1:26 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.6  0.3404928395872 pts/32   S 08:23:35  1:32 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.5  0.3409024399968 pts/32   S 08:23:35  1:39 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.5  0.3409024399968 pts/32   O 08:23:35  1:45 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.5  0.4429760421056 pts/32   O 08:23:35  1:52 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.6  0.4429760421064 pts/32   S 08:23:35  2:00 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.6  0.4429760421064 pts/32   O 08:23:35  2:07 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.6  0.4429760421064 pts/32   O 08:23:35  2:13 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.5  0.4429760421064 pts/32   S 08:23:35  2:19 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4
arbsfr    8331  0.6  0.4429760421256 pts/32   O 08:23:35  2:27 /export/home/arbsfr/helen/797/bin/CAP.yy cap08 4


你可能感兴趣的:(如何查看CPU 占用率)