linux脚本判断进程不在就重启进程,Linux下检测程序进程是否正常并重启的脚本...

#!/bin/sh

#set program name

ProgramFile=WDWifiDetector

#----------------------------------------------The following contents are prohibited to modify by the user-------------------------------------------

while((1>0))

do

pid=$(pgrep $ProgramFile)

echo $ProgramFile pid=$pid

#pgrep $ProgramFile>/dev/null:检测进程是否存在

#echo $pid|grep -c ' '>/dev/null:检测进程的个数,如果程序中用了诸如fork等函数启动了额外的进程,则需要检#测进程的个数,$pid中进程号和进程号是空格隔开,用grep统计空格个数;如果只有一个进程则下面的if不需要此判断

if (pgrep $ProgramFile>/dev/null) && (echo $pid|grep -c ' '>/dev/null)

then

echo $ProgramFile progress is exist!

else

echo $ProgramFile progress is not exist or incomplete.Ready to launch the program......

pgrep $ProgramFile|xargs kill -s 9

sleep 60

$ProgramFile &

echo $ProgramFile is launched.....

fi

sleep 10

done

exit 0