分类: LINUX
2011-07-13 17:57:00
一直以为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使用率,也就是
而ps命令中的cpu使用率,反映的是该进程启动以来使用系统资源的情况:
两者有很大的区别。
(上述所说的ps和top命令所在的操作系统是debian)。