When I execute following command to get cpu usage , I get nice + user cpu usage.
top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'
Output:
14.5
Here I am getting problem is that the output depends on top command thus it doesn't change instantly as top command. So I am not getting correct cpu instantly. It gives same output and not changing.
I want to get realtime cpuusage in output. Please help me to improve my command.
time
. On my system it only takes 0.165s. – depquid Mar 26 '13 at 18:16time (top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}' )
– depquid Mar 28 '13 at 20:59