如何写一个脚本,检测如果python程序终止,立即重启? python|bash|Linux

假设存在一个task.py,由于长时间工作内存溢出的问题,可能终止。如何检测他停止任务,立即重启他?

import time

while(1):

    print('.')

    # 模拟异常终止

    sleep(2)

    exit(0)

感谢!!!!!

慕莱坞森
浏览 1332回答 3
3回答

米琪卡哇伊

也可以利用 systemd:Restart=always RestartSec=0

慕神8447489

supervisor写一个shell脚本function check(){      count=`ps -ef |grep $1 |grep -v "grep" |wc -l`      #echo $count      if [ 0 == $count ];then        nohup python $1 &      fi    }

www说

supervisord
打开App,查看更多内容
随时随地看视频慕课网APP