1、首先看了这个同学的文档:https://blog.csdn.net/weixin_38860565/article/details/102774643
下边是他的代码
#!/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
又看了两个同学的文档:https://blog.csdn.net/weixin_42840933/article/details/85780125
:https://blog.csdn.net/suixinsuoyu12519/article/details/84975275
学习上述命令:
注: ps: 查找运行的进程,就是查看需要监控的程序是否还在运行(-v:这个参数是反向查找)
2>&1:
是一个整体,>
左右不能有空格,即将错误内容重定向输入到标准输出中去。
nohup: 这个命令就是重启进程进行后台运行。
“ nohup python -u test.py 12 > nohup.out 2>&1 & ”这条命令的意义:
解释: 以python环境不间断的运行my.py这个脚本,并且将脚本输出的内容重定向输入my.log
中(>>
意为追加,如果用>
会让其中的内容清空)