import subprocess as sb
import time,sys,datetime
count = 1
while True:
try:
count += 1
res = sb.getoutput("ps -ef|grep python3") #查看是否还在运行中,
if "zdjy" in res:#判断
print('运行正常',datetime.datetime.now())
# res = res.split(" ")
# for i in res:
# if "zdjy" in i:
# print(i)
# res2 = i.split(" ")[1]
# num = res2.strip()
else:
print('找不到进程,重新启动',datetime.datetime.now())
sb.getoutput("nohup python3 zdjy(1).py &")
time.sleep(10)
print(count)
except:
pass