linux - top與ps間的區別

背景

  在linux系統中提供了2個查詢系統負荷值的命令,一個是 ps -o THREAD 一個是 top ,這兩個命令都可以查詢當前進程的CPU使用率狀況,可是所表明的含義確實不同的,ps -o THREAD 偏向與整個進程週期所佔的CPU使用率,而 top 更偏向於某個固定時間窗口的CPU使用率也就是說更傾向於查詢實時CPU使用率。linux

具體

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上所花費的時間 百分比express

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時間與該單位時間的百分比值。ide

總結

  1. ps -o THREAD 命令更偏向於整個進程生命中佔用CPU時間的比率
  2. top 命令更偏向於某個時間點佔用CPU時間的比率
相關文章
相關標籤/搜索