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()

  • 相关阅读:
    Haskell 编写几个递归函数 练习 typeclass 模式匹配等
    Haskell-chp01
    阉割的List
    实现简单的string类
    构造函数语义学——Copy Constructor 的构造操作
    BinarySearchTree-二叉搜索树
    对象模型
    二叉树的遍历
    带头尾结点的单链表
    Effective Modern C++ ——条款5 优先选择auto,而非显式型别声明
  • 原文地址:https://www.cnblogs.com/linn/p/1362725.html
Copyright © 2011-2022 走看看