代码示例:
#!/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
本文标题:Linux:Shell 检测一个进程是否正在运行
本文链接:https://www.haomeiwen.com/subject/bxwxfctx.html
网友评论