top command first iteration always returns the same result

后端 未结 5 915
故里飘歌
故里飘歌 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:25

    if anyone is looking for a one line get the value of cpu then try this

    top -b -n 5 -d.2 | grep "Cpu" | tail -n1 | awk '{print($2)}' | cut -d'%' -f 1

提交回复
热议问题