您的位置:首页 > 运维架构

ps和top命令的%CPU含义

2010-06-09 10:13 393 查看
一直以为ps命令中的"%CPU"也是指实时的CPU使用率,所以一直都用它来做cacti监控process的cpu使用率。但是上周发现有点不对,ps的"%CPU"与top或者vmstat 的"%CPU"不一样。

ps命令的man里面的解释:
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%.

top命令的man的解释:
k: %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 'Irix mode' is Off, top will operate in number of CPUs. You toggle

'Irix/Solaris' modes with the 'I' interactive command.

我的理解是,top中的进程cpu使用率,是实时的CPU使用率,也就是

单位时间内进程使用的CPU时间/单位时间

而ps命令中的cpu使用率,反映的是该进程启动以来使用系统资源的情况:

进程启动以来使用的CPU时间/进程启动以来的实际时间

两者有很大的区别。

(上述所说的ps和top命令所在的操作系统是debian)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: