监控进程脚本

如果程序经常挂掉,且找不到解决的办法时候,可以使用shell写一个进程监控脚本,以便程序挂掉,可以立即自动重启,以下是监控进程一个例子。
shell语言编程参考https://www.runoob.com/linux/linux-shell.html

#!/bin/bash
while true; do
if
   # 判断应用的进程是否存在
    ps -ef |grep test.py | grep -v "grep"   
then
    echo ">>>>it running"
else
   # 不存在,重新启动
    nohup python -u test.py 12 > nohup.out 2>&1 & 
    echo ">>>>no run it"
fi
   # 每隔5秒扫描监控
   sleep 5
done
发布了68 篇原创文章 · 获赞 12 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_38860565/article/details/102774643