I'm trying to get the CPU percentage for processes on a busy server out of ps
, but it's giving me nonsensical numbers. Here's a truncated example:
$ ps -eo pcpu,pid | sort -n
%CPU PID
...
36.5 26403
38.6 28295
39.0 11741
42.6 11736
58.6 15960
61.4 21989
63.0 21939
65.5 18017
66.0 20708
67.3 22040
73.2 31950
80.0 11740
83.6 22091
109 16648
171851 22888
171851 22938
171856 23191
171858 23241
171866 24681
171875 26996
171895 30277
172376 26084
172449 25530
top
reports a CPU% of 0.0 for the later pids. What's going on here? How can I convince ps
to give me the right CPU% number here? As an alternative, is is possible to tell top -b -n1
to give me the full ARGV for the processes it's reporting? The man page is unilluminating.
EDITED TO ADD:
If I do a ps -eo pcpu,pid --sort -pcpu | head
, I still get bad numbers:
%CPU PID
343702 23762
343653 22570
109 16648
83.6 22091
73.3 31950
67.3 22040
66.0 20708
EDITED FURTHER TO ADD:
The systems I've seen this on so far are both real hardware: x86_64 Debian Squeeze systems, one with the 2.6.32-5-amd64 kernel, and the other with 2.6.39-bpo.2-amd64. The former has 32 cores, the latter 12. One's an Opteron with 192GB RAM, the other a Xeon with 72GB.
The more I look at this, the more it looks like a simple bug in ps
that shows high numbers for processes with very little activity, but I don't want to rely on that until I know more.