Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running a quite heavy number crunching thing on a few 4 core servers, all running Ubuntu Precise Pangolin LTS 64 bit, in the cloud (so I suppose in a virtualized environment).

To monitor the cpu usage, i wrote a .sh that uses "top -b -n 1" (that is a single run of top, only the first "frame") and merges it with some other data, to write a small report.

However, top always reported 64% idle on the cpus line, for each server, even if I was quite sure all four cores were 100% busy.

In fact, running top interactively, in the first frame it reports 64% idle time, but as soon as it refresh it reports correct (nearly 0% idle) data.

vmstat too, in the cpu column, always reports 64% idle time on the first line, and then starts reporting (supposedly) real data.

Why is it? Is it a bug in top/vmstat or in the kernel? Or is it a known side effect of how cpu % is measured? Why always 64%?

cpu load is instead always correct (around 4).

share|improve this question

1 Answer 1

This is because top, vmstat, iostat all in their first run collect data since the last reboot time of the system.

And the successive iterations run on the sampling period that you specify. So, in the first run of top, you will see the %idle time because from the time of reboot to the time of running top, it was that much % idle. But in next iterations, since it is busy it doesn't show any %idle.

Exclude the first iteration and try sampling over the interval you want.

share|improve this answer
Nice, always something new to learn. However, how does I tell top to give me the last second and all the life of the server when using -b? I need -b to capture the output of top to a report file. –  Simone Gianni Oct 9 '12 at 21:32
I don't understand your requirement. Can you elaborate a bit please. Do you want the stats since the last reboot time along with the sampling period you are looking for. If you have specific time requirement between iterations of top use the -d switch, where you can specify delay. –  Soham Chakraborty Oct 10 '12 at 6:47
Hi Soham, thanks for your answer. I need to capture the output of top and place it in a file, not look at it interactively. That's what the -b (batch) option is there for. I use "top -b -n 1". However, I want, in that file, the current (last second sample) situation, not the situation since the server booted. How can I achieve this? I tried "top -b -n 1 -d 1" but it does not change anything. I could do "top -b -n 2 -d 1" and "filter out" (using awk?) the second "screen", but was searching for a simpler way. –  Simone Gianni Oct 10 '12 at 10:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.