zoukankan      html  css  js  c++  java
  • WINDOWS PHP-CGI频繁掉线,PYTHON进程监控来曲线救国

    执行环境:python33

    import threading
    import time
    import os
    import subprocess
    
    php_cgi_name = 'php-cgi.exe';
    php_cgi_path = 'D:/wamp/php/5.5.10/php-cgi.exe';
    php_cgi_arg = "-b127.0.0.1:9000 -cD:/wamp/php/5.5.10/php.ini";
    
    def get_process_count(imagename):
        p = os.popen('tasklist /FI "IMAGENAME eq %s"' % imagename)
        return p.read().count(imagename)
     
    def timer_start():
        t = threading.Timer(1,watch_func)
        t.start()
    
    def watch_func():
        if get_process_count(php_cgi_name) == 0 :
            print("{0} 正在重启:{1},进程:{2}".format(time.strftime("%Y-%m-%d %H:%M:%S"), php_cgi_name, subprocess.Popen([php_cgi_path, php_cgi_arg])))
        timer_start()
    
    if __name__ == "__main__":
        timer_start()
        while True:
            time.sleep(1)
  • 相关阅读:
    such用法
    divorce用法
    towel用法
    go for用法
    catch on用法
    incredibly用法
    mess用法
    dentist用法
    steer clear of用法
    incredible
  • 原文地址:https://www.cnblogs.com/mtima/p/3686053.html
Copyright © 2011-2022 走看看