htop和ps aux输出之间的巨大差异

时间:2016-03-09 10:02:35

标签: ubuntu-14.04 cpu-usage ps htop

我在Ubuntu 14.04上运行测试。当我使用时检查我的CPU使用情况 'ps aux | grep service'然后CPU使用率是一个进程的0.1,而在同一进程的htop中,CPU%是12.3。

谁能告诉我原因?或者我认为哪个价值合适?

由于

1 个答案:

答案 0 :(得分:2)

他们正在测量不同的东西。

来自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%.   

来自htop手册页(我是htop的作者):

   PERCENT_CPU (CPU%)
        The  percentage  of  the  CPU  time  that the process is currently
        using.

因此,在htop中,这是程序在上次刷新屏幕与现在之间使用的总CPU时间的百分比。

PercentageInHtop =(过去1.5秒内进程使用的非空闲CPU时间)/ 1.5s

ps中,这是程序使用的CPU时间相对于其存在的总时间的百分比(即,自启动以来)。

PercentageInPs =(进程启动后进程使用的非空闲CPU时间)/(自进程启动以来经过的时间)

也就是说,在您的阅读中,这意味着htop表示该服务占用了CPU 的12.3%,而ps表示您的服务已经花了99.9%的总生命闲置。