【发布时间】:2016-06-23 15:20:07
【问题描述】:
我正在 Ubuntu 14.04 上运行测试。当我使用 'ps aux|grep service' 那么 CPU 使用率是一个进程的 0.1,而在 htop 中,同一进程的 CPU% 是 12.3。
谁能告诉我原因?或者我应该考虑哪个值是正确的?
谢谢
【问题讨论】:
标签: ubuntu-14.04 cpu-usage ps htop
我正在 Ubuntu 14.04 上运行测试。当我使用 'ps aux|grep service' 那么 CPU 使用率是一个进程的 0.1,而在 htop 中,同一进程的 CPU% 是 12.3。
谁能告诉我原因?或者我应该考虑哪个值是正确的?
谢谢
【问题讨论】:
标签: ubuntu-14.04 cpu-usage ps htop
他们正在测量不同的东西。
来自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%,而 ps 表示您的服务已占用 99.9% 的 CPU它的整个生命周期都是空闲的。
【讨论】: