How to get current cpu usage?

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
Using standard linux (Ubuntu) commands, how do I get the printout of the current cpu usage. I will be capturing that text, so the program cannot loop/refresh. So, 'top' is not an option. 'mpstat' would be good, but it only shows avg since reboot.
 

Fallen Kell

Diamond Member
Oct 9, 1999
6,161
510
126
Someone needs to read the man pages...

top -b -n 1

Will do exactly what you want.
 

Ross Ridge

Senior member
Dec 21, 2009
830
0
0
I would think that "mpstat" does exactly what you want. Just run something like "mpstat 1 > cpu-usage.log" and it'll capture the CPU usage every second to a file.
 

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
Thanks guys. I did do quite a bit of google searching for a solution before I resorted to posting here.

I think I'll try 'top -b -n 1' first.
 

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
Someone needs to read the man pages...

top -b -n 1

Will do exactly what you want.

I finally got a chance to try this out. Unfortunately it doesn't work as expected. It also gives me the same % as mpstat, which isn't the current cpu usage but average for entire uptime, unless refreshing.

I decided to use this: 'top -b -n 2'

The 2nd iteration is the one with the current cpu usage.