1. 程式人生 > >每隔幾秒檢測進程是否掛了

每隔幾秒檢測進程是否掛了

col nbsp art net pytho sys hup pre python re

#!/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 &

每隔幾秒檢測進程是否掛了