检测进程,判断是否需要重启


while true

do
ps aux | grep ProgramName | grep -v grep //-v 在文档中过滤掉包含有grep字符的行
if [ $? -eq 0 ];then             //$? 判断上个程序退出状态码, 0 默认成功
#找到了
sleep 5
else
#没找到,启动
fi
done

//$n        $1 the first parameter,$2 the second...
//$#        The number of command-line parameters.
//$0        The name of current program.
//$?        Last command or function's return value.
//$$        The program's PID.
//$!        Last program's PID.
//$@        Save all the parameters.
posted @ 2014-06-23 15:42  望远近  阅读(356)  评论(0编辑  收藏  举报