top command first iteration always returns the same result

后端 未结 5 854
故里飘歌
故里飘歌 2021-01-12 16:12

When running top -b -n 1, the command always returns the same CPU values. Consider the following test run 5 times in succession:

[user@server ~]$ top -b -n          


        
5条回答
  •  南笙
    南笙 (楼主)
    2021-01-12 16:42

    Top doesn't know what process time counts were before it starts, so it makes a guess in the first pass, based on a variety of factors like load average and waiting threads.

    You can see the same effect if you start top interactively and quickly examine the first batch of results it returns.

    Simple solution: top -b -n 5 -d.2 | grep "Cpu(s)" | tail -n+2

提交回复
热议问题