python监控程序是否运行中,如果没有运行则调用该程序:
#coding:utf-8
import psutil
import os,sys,time
def start():
msn=0
for i in psutil.pids():
#print psutil.Process(i).name()
if psutil.Process(i).name().find("BiliDuang1.exe")>=0:
#print psutil.Process(i).name()#,psutil.Process(i).cwd(),psutil.Process(i).cmdline()
msn=1
else:
pass
if msn==1:
print 'process is found.'
else:
print 'process is not foud,','\r\nbegin to run it:'
os.system('C:\\Users\\**\\Desktop\\**\\2.1.7.Preview\\***.exe')
def main():
while True:
print time.time()
try:
start()
except Exception as e:
print e
if __name__ == '__main__':
main()
https://www.jb51.net/article/138123.htm