linuxtop与ps间的区别

编程

背景

  在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时间的比率。

以上是 linuxtop与ps间的区别 的全部内容, 来源链接: utcz.com/z/512759.html

回到顶部