ps 和 top cpu 佔用區別

轉載自: http://blog.csdn.net/beginning1126/article/details/8057527

ps和topcpu 佔用區別

但試了一會發現個不小的問題,把包含flash的網頁關掉後,ps顯示它的cpu佔用率還是居高不下。奇怪了,難道它還在後臺工作嗎?我又用top看了下,更奇怪了,top顯示flash佔用的cpu分明是0。又等了一會,ps顯示的還是好幾十。
以前好像也發現過這樣的問題,但以爲是誤差等問題也沒細想,但今天看這顯然和誤差什麼的沒關係。
上網找了找,終於明白了。

看看man ps裏的相關內容
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%.

再看看top的
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
‘Solaris mode’ where a task’s cpu usage will be divided by the
total number of CPUs. You toggle ‘Irix/Solaris’ modes with the
‘I’ interactive command.

就不難理解了。ps是從進程開始就開始算的,是平均的佔用率;而top是從上次刷新開始算的,一般幾秒鐘一刷,可以認爲是即時的。而桌面系統我們一般更關注即時的,所以top的cpu佔用率纔是我需要的。而且top默認cpu的佔用率的和並不是100%,而是核數x100%,所以有時會有一個進程佔用超過100%的情況。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章