【问题标题】:Huge difference between htop and ps aux output [closed]htop和ps aux输出之间的巨大差异[关闭]
【发布时间】: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


    【解决方案1】:

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

    来自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它的整个生命周期都是空闲的。

    【讨论】:

    • 我没听懂。我同时收集了上面的阅读。如果 ps 显示自进程启动以来进程的 cpu% 使用率,它应该大约等于或逻辑上大于 htop,因为 htop 显示的是我在终端中编写 htop 后的读数,对吧?
    • 没有。 htop 这是程序在上次刷新屏幕(上次重新计算值的时间)和现在(换句话说,在最后 1.5 秒内,默认情况下)之间使用的总 CPU 时间的百分比)。
    • 不应该小于ps吗??
    • 不,它们真的是完全不同的东西! htop 中的使用率可能会因为临时峰值而很高,并且进程的总生命周期使用(由 ps 反映)可能仍然很低。我在上面的答案中添加了方程式以更清楚地解释它。
    猜你喜欢
    • 2013-12-27
    • 2016-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多