zoukankan      html  css  js  c++  java
  • linux

    背景

      在linux系统中提供了2个查询系统负荷值的命令,一个是 ps -o THREAD 一个是 top ,这两个命令都能够查询当前进程的CPU使用率情况,但是所代表的含义确实不一样的,ps -o THREAD 偏向与整个进程周期所占的CPU使用率,而 top 更偏向于某个固定时间窗口的CPU使用率也就是说更倾向于查询实时CPU使用率。

    具体

    NOTES
           This ps works by reading the virtual files in /proc.  This ps does not need to be setuid kmem or have any privileges to run.  Do not give this ps any special permissions.
    
           This ps needs access to namelist data for proper WCHAN display.  For kernels prior to 2.6, the System.map file must be installed.
    
           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%.
    

      从第三行 CPU usage is currently expressed as the percentage of time spent running during the entire lifetime of a process 可知 CPU使用率表示为进程整个生命周期中 与 运行在CPU上所花费的时间 百分比

    1. %CPU  --  CPU Usage
               The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.
    
               In a true SMP environment, if a process is multi-threaded and top is not operating in Threads mode, amounts greater than 100% may be reported.  You toggle Threads mode
               with the `H' interactive command.
    

      根据 CPU Usage The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.知道CPU使用率是在一个单位时间窗口下该进程占用CPU时间与该单位时间的百分比值。

    总结

    1. ps -o THREAD 命令更偏向于整个进程生命中占用CPU时间的比率
    2. top 命令更偏向于某个时间点占用CPU时间的比率
  • 相关阅读:
    URAL 2034 : Caravans (二分最短路)
    Qt程序的字符编码方式
    Qt程序国际化
    Qt5 + msvc2015编译器 环境配置 (不安装VS)
    error: undefined reference to `Dialog::on_pushButton_clicked()'在程序代码的后台程序代码出现问题
    Qt的inherits()函数判断qt控件是否为某个类实例
    WPS使用书签跳转到指定的文档位置
    Qt error ------ 出现Error
    环境名词
    source insight 联想出Qt库函数
  • 原文地址:https://www.cnblogs.com/cjunn/p/12196085.html
Copyright © 2011-2022 走看看