代码示例:
#!/bin/bash
while true
do
count=`ps -ef | grep 进程名 | grep -v "grep" | wc -l`
if [[ $count == 0 ]];then
echo "已经停止运行"
else
sleep 5
fi
done
持久化检测(后台运行)
setsid ./shell名.sh
#!/bin/bash
while true
do
count=`ps -ef | grep 进程名 | grep -v "grep" | wc -l`
if [[ $count == 0 ]];then
echo "已经停止运行"
else
sleep 5
fi
done
setsid ./shell名.sh