ps和top命令的%CPU含义

转自:http://www.joecen.com/2008/04/15/ps-top-cpu-mean/

-----------------------------

一直以为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)。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值