linux系统 python 程序,Linux系统重启python程序,, 1 #! /usr

Linux系统重启python程序,, 1 #! /usr1 #! /usr/bin/env python 2 #coding=utf-8 3 4 import sys 5 import ConfigParser 6 import urllib 7 import urllib2 8 from util import http_server 9 from logger import logger10 import json11 import traceback12 import time13 14 reload(sys)15 sys.setdefaultencoding(‘utf-8‘)16 17 import os18 import signal19 20 Max_process = 221 log_index = 022 23 # start python program24 def start():25 global Max_process26 global log_index27 path = os.popen(‘pwd‘).readlines()[0]28 print path,‘===‘29 os.system(‘nohup python serverdate.py &‘)30 time.sleep(10)31 32 #stop child33 def stopChild():34 processInfo = os.popen("ps -ef|grep serverdate.py|grep -v grep|awk ‘{print $2}‘").readlines()35 print processInfo,‘------‘36 for pid in processInfo:37 os.kill(int(pid),signal.SIGKILL)38 39 #stop parent40 def stopParent():41 parentList = os.popen("ps -ef|grep serverdate.py|grep -v grep|awk ‘{print $2}‘").readlines()42 print parentList,‘***‘43 for pid in parentList:44 os.kill(int(pid),signal.SIGKILL)45 46 def stopAll():47 stopChild()48 stopParent()49 50 try:51 fun = sys.argv[1]52 except Exception:53 fun = ‘‘54 if(fun == ‘start‘):55 start()56 if(fun == ‘stop‘):57 stopAll()58 if(fun == ‘restart‘):59 stopAll()60 time.sleep(10)61 start()

使用方法:python serverdate.py start|stop|restart

Linux系统重启python程序

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值