我正在 Ubuntu 14.04 上运行测试。当我使用“ps aux|grep service”检查我的 CPU 使用率时,CPU 使用率是一个进程的 0.1,而在同一进程的 htop 中,CPU% 是 12.3。
谁能告诉我原因?或者我应该考虑哪个值是正确的?
谢谢
我正在 Ubuntu 14.04 上运行测试。当我使用“ps aux|grep service”检查我的 CPU 使用率时,CPU 使用率是一个进程的 0.1,而在同一进程的 htop 中,CPU% 是 12.3。
谁能告诉我原因?或者我应该考虑哪个值是正确的?
谢谢
他们正在测量不同的东西。
从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.5 秒
这ps
是程序使用的 CPU 时间相对于它存在的总时间(即,自启动以来)的百分比。
PercentageInPs =(自进程启动以来进程使用的非空闲 CPU 时间)/(自进程启动以来经过的时间)
也就是说,在您的阅读中,这意味着该服务现在htop
占用了您的 CPU 的 12.3% ,而您的服务已经花费了其总生命周期的 99.9% 空闲。ps