Procps: top -b does not display the correct CPU percentages
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
procps (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Affects: 2:3.3.12-3ubuntu1.2 (bionic) & 2:3.3.10-4ubuntu2.4 (xenial)
If I run 'top -b -n 1' the CPU percentages are the same every single time. If I run with more iterations the CPU percentages of subsequent iterations update in real time. If I run top interactively then the CPU percentages correctly update in real time. Here's an example.
1) With n=1 the same CPU percentages are always displayed.
while true ; do top -b -n 1 | grep -E "^%Cpu" ; sleep 10; done
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
2) With n=2 the second iteration shows a changing CPU percentage, but the first is still clearly wrong.
while true ; do top -b -n 2 | grep -E "^%Cpu" ; sleep 10; done
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 27.3 us, 1.7 sy, 0.0 ni, 70.5 id, 0.0 wa, 0.0 hi, 0.4 si, 0.0 st
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 50.9 us, 5.4 sy, 0.0 ni, 42.2 id, 0.1 wa, 0.0 hi, 1.4 si, 0.0 st
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 63.3 us, 5.2 sy, 0.0 ni, 29.2 id, 0.1 wa, 0.0 hi, 2.2 si, 0.0 st
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 43.3 us, 2.9 sy, 0.0 ni, 52.4 id, 0.1 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 38.0 us, 3.7 sy, 0.0 ni, 56.8 id, 0.2 wa, 0.0 hi, 1.4 si, 0.0 st
%Cpu(s): 46.1 us, 4.1 sy, 0.2 ni, 48.1 id, 0.2 wa, 0.0 hi, 1.2 si, 0.0 st
%Cpu(s): 47.9 us, 3.5 sy, 0.0 ni, 47.2 id, 0.1 wa, 0.0 hi, 1.2 si, 0.0 st
This affects both Xenial and Bionic.