shell编写简单的守护进程

[codesyntax lang=”bash”]

#!/bin/sh
PRO_PATH=”/home/sh”
PROGRAM=”rediscache.sh”

while true ; do
PRO_NOW=`ps aux | grep $PROGRAM | grep -v grep | wc -l`

if [ $PRO_NOW -lt 3 ]; then
#echo “exec $PROGRAM”
$PRO_PATH/$PROGRAM 2>/dev/null 1>&2 &
fi

PRO_STAT=`ps aux|grep $PROGRAM |grep T|grep -v grep|wc -l`

if [ $PRO_STAT -gt 0 ] ; then
killall -9 $PROGRAM
./$PROGRAM 2>/dev/null 1>&2 &
fi
sleep 2
done
exit 0

[/codesyntax]

shell编写简单的守护进程》有2个想法

评论已关闭。