#! /bin/sh
#Process name can be modified shipInfo
PRO_NAME=shipInfo
WLAN=ra0
while true; do
# Use ps to get the number of $PRO_NAME processes
NUM=`ps aux | grep ${PRO_NAME} | grep -v grep |wc -l `
# echo $NUM
# Less than 1, restart the process
if ["${NUM}" -lt "1" ]; then
echo "${PRO_NAME} was killed"
./shipInfo
# ${PRO_NAME} -i ${WLAN }
# Greater than 1, kill all processes, restart
elif ["${NUM}" -gt "1" ];then
echo "more than 1 ${PRO_NAME},killall ${PRO_NAME}"
killall -9 $PRO_NAME
${ PRO_NAME} -i ${WLAN}
fi
# kill the zombie process
NUM_STAT=`ps aux | grep ${PRO_NAME} | grep T | grep -v grep | wc -l`
if ["${NUM_STAT}" -gt "0" ];then
killall -9 ${PRO_NAME}
${PRO_NAME} -i ${WLAN}
fi
done
exit 0
Write a daemon under linux
Guess you like
Origin blog.csdn.net/qq_14874791/article/details/110161060
Ranking