# !/bin/sh
#
not_done=1
cntr=0
# Look for process firefox every 1 seconds
while [ "$not_done" -eq 1 ]
do
top -b -n 1 | grep "firefox" >> /tmp/firefox.out
sleep 1
((cntr=cntr+1))
# Addition logic to break out of loop after 10 iterations
if [ "$cntr" -eq 10 ]
then
not_done=0
fi
echo "cntr=$cntr"
done
2条答案
按热度按时间xxslljrj1#
您需要
top
的-n
参数。例如,如果没有
-n 1
,top
将继续处理,永远不会到达grep
..top
得手册页中:使用
while
循环更新代码。除非使用类似cntr
变量的内容,否则它将永远循环。如果要连续监视,请删除cntr
代码:bd1hkmkf2#
您必须在命令中添加标志-n来更改要显示的进程数。系统将提示您输入数目。
要在top实用程序中创建特定进程的快照,请执行带有PID(-p)标志的命令。
如果你想为进程1(PID)拍摄快照,我也建议你拍摄PID的三个快照:顶部-p 678 -B -n3〉监控输出