import os
import sys
import time
import subprocess
def get_process_id(name):
"""查询进程ID"""
child = subprocess.Popen(["pgrep","-f",name],stdout=subprocess.PIPE,shell=False)
pid = child.communicate()[0]
return pid
while True:
pid = get_process_id("python test.py") # 要守护的程序文件
if not pid:
print 'not pid, Reboot'
os.system("nohup python test.py &") # 重新开启进程
time.sleep(60)