为了防止程序死掉,写的一个守护程序

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里。重新执行下
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值