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

  • 相关阅读:
    VS 2010 Addin 开发 1
    事件冒泡和默认事件
    闭包试验
    查询字符串中出现频率最高的几种方法
    JS函数中的参数
    a 项目已更新,b 项目可以基于这个项目处理
    windows 生成ssh 公钥 命令
    git fetch upstream 报错 XXX Permission denied (publickey). fatal: Could not read from remote repository
    考试的那点事儿
    MySQL数据库InnoDB存储引擎多版本控制(MVCC)实现原理分析
  • 原文地址:https://www.cnblogs.com/linn/p/1362725.html
Copyright © 2011-2022 走看看