每隔几秒检测进程是否挂了

#!/usr/bin/python
# -*- coding: UTF-8 -*-
# @date: 2017/11/27 23:15
# @name: restart_myblog
# @author:vickey-wu

import os
import time

def restart():
    is_alive = os.system("netstat -anp | grep python")
    if is_alive:
        os.system("python /home/myblog/manage.py runserver")


if __name__ == '__main__':    
    while 1:
        restart()
        time.sleep(2)

后台运行:nohup python restart_myblog.py &

原文地址:https://www.cnblogs.com/vickey-wu/p/7906686.html