zoukankan      html  css  js  c++  java
  • Linux下用PYTHON查找同名进程

    1.可执行程序

    os.system('pgrep %s > %s' % (process, output))
       pidfile = open("output", 'r')
       totalpid = len(pidfile.readlines())

       pidfile.close()
       if totalpid == 0 :
                                    #没有进程
                                    return False
                            elif totalpid > 1 :
                                    #多个进程
                                    os.system('killall -9 %s' % (process))
                                    return False
                            else :
                                    return True   

    2.python 启动的脚本

    os.system('ps aux | grep %s > %s' % (process, output))
                            pidfile = open(output, 'r')
                            totalpid = len(pidfile.readlines())
                            pidfile.close()
                            while totalpid > 3 :
                                    os.system("kill -9 `ps aux | grep %s | sed -n '1P' | awk '{print $2}' ` " % (process))
                                    os.system('ps aux | grep %s > %s' % (process, output))
                                    pidfile = open(output, 'r')
                                    totalpid = len(pidfile.readlines())
                                    pidfile.close()

  • 相关阅读:
    精通正则表达式(JavaScript)
    Go知识点记录
    多线程揭秘
    Python test
    ELinq+T4模版引擎制作多文件实体代码生成器
    浏览器内核
    MongoDb的增删改查
    LINQ执行表达式
    ASP.NET MVC3 读书笔记四(数据注解和验证)
    C#默认以管理员身份运行程序
  • 原文地址:https://www.cnblogs.com/linn/p/1362725.html
Copyright © 2011-2022 走看看