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

ano*_*255 1 cpu-usage ps htop ubuntu-14.04

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

谁能告诉我原因吗?或者我应该考虑哪个值是正确的?

谢谢

His*_*H M 6

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

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%.   
Run Code Online (Sandbox Code Playgroud)

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

   PERCENT_CPU (CPU%)
        The  percentage  of  the  CPU  time  that the process is currently
        using.
Run Code Online (Sandbox Code Playgroud)

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

PercentageInHtop =(最近 1.5 秒内进程使用的非空闲 CPU 时间)/ 1.5 秒

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

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

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