Skip to content

cpu_pstop

遇见王斌 edited this page Mar 23, 2017 · 1 revision

ps和top中的CPU

ps中的CPU

ps命令的man里面的解释:

CPU usage is currently expressed as the percentage of time spent running during the entire lifetime of a process. This is not ideal, and it does not conform to the standards that ps otherwise conforms to. CPU usage is unlikely to add up to exactly 100%.

ps命令中的cpu使用率,反映的是该进程启动以来使用系统资源的情况:

进程启动以来使用的CPU时间/进程启动以来的实际时间,其值不可能大于100%

top的CPU

top命令的man的解释:

k: %CPU -- CPU usage
The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU
time. In a true SMP environment, if 'Irix mode' is Off, top will operate in number of CPUs. You toggle
'Irix/Solaris' modes with the 'I' interactive command.

top中的进程cpu使用率,是实时的CPU使用率,也就是

单位时间内进程使用的CPU时间/单位时间

检测某进程的cpu的正确做法

#process_pid=$(ps -ef | grep 进程名 |awk '{print $2}')
#top -n 1 -p  ${process_pid}| grep ${process_pid} | awk '{print $10}'
Clone this wiki locally