如果程序經常掛掉,且找不到解決的辦法時候,可以使用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