Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the very first top command result on Linux credible?

Tags:

linux

bash

shell

When I execute shell scripts bash.sh like this:

for((i = 0; i<=5 ;i++))
do
  ./test.sh &
done

and test.sh like this:

for((i = 0; i<=10000000 ;i++))
do
  echo 'hh'
done

the cpu us usage should be very high.

But when I use top command to check the result, the cpu us value of the very first time of the top command result, before it refreshes, is very small.

So the cpu usage is not credible!

Are the other values credible the first time top command result refresh?

like image 348
Derek Hu Avatar asked Oct 14 '25 17:10

Derek Hu


1 Answers

The load average reported on the top right is the average over the last 1, 5 and 15 minutes (from the man top page):

system load avg over the last 1, 5 and 15 minutes

So this value will be averaged over the last minute, and as a result your process with a high CPU usage will not have an immediate effect on it.

The %CPU column shows the usage since the last update:

The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time

So on the first time, the %CPUs are off and will change when the screen updates.

like image 144
Benedikt Köppel Avatar answered Oct 17 '25 09:10

Benedikt Köppel