top command in shell script

耗尽温柔 提交于 2019-12-06 16:00:18

You need to run top in batch mode instead of the default interactive mode. In addition you need to define the number of iterations that top performs for getting its measurements.

num_iterations=3
top -b -n $num_iterations | head -5

If you want the output to only list the top 5 processes and skip the statistic header displayed, you can try this:

num_iterations=3
top -b -n $num_iterations | sed -n '8,12p'

Also tune the value of num_iterations as per your need.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!