背景 在linux系統中提供了2個查詢系統負荷值的命令,一個是 ps o THREAD 一個是 top ,這兩個命令都能夠查詢當前進程的CPU使用率情況,但是所代表的含義確實不一樣的, ps o THREAD 偏向與整個進程周期所占的CPU使用率,而 top 更偏向於某個固定時間視窗的CPU使用率也 ...
背景
在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時間與該單位時間的百分比值。
總結
- ps -o THREAD 命令更偏向於整個進程生命中占用CPU時間的比率。
- top 命令更偏向於某個時間點占用CPU時間的比率。