import glob,os,stat,time,sys
def main():
while True:
retcs = int(os.popen("ps aux|grep ./chat |wc -l").read())
log('The System runing..%d.' % retcs)
if retcs <2:
os.system("./chat")
log('reboot...')
f = file('LOG/CS_LOG.txt','a')
fs_log = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())+"/n"
f.write(fs_log)
f.close()
time.sleep(30)
return
def log(str):
print >>sys.stderr, str
if __name__ == "__main__":
main()
比较简单,就是每过30秒。去看下进程数,如果=1,说明只有grep ./chat 命令在ps里。重新执行下