Search code examples
linuxcpups

Linux's top CPU usage - always the same value


Here is my command:

top -b -n 1 | head -3 | tail -n 1 | awk '{ print $2 }'

I run a bash script which gets these details (also Load Average and memory consumption) and saves it to a file, which I use to visualise cpu load.

But the above command, shows always the same value! ~6%, no matter if the server is under heavy load or idle.

when I run:

top

It shows the same value (~6%) at the beginning, and after refresh it shows real value (eg. 80%).

How to fix that, or how to get current cpu usage, which can be used for visualisation?


Solution

  • I didn't know it's called "iteration", using this keyword I've found a solution for the issue:

    top command first iteration always returns the same result

    Thank you for your help!