推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
pengdu
V2EX  ›  Python

记一个python中判断进程死活的方法

  •  
  •   pengdu ·
    pengdu · Apr 11, 2013 · 5148 views
    This topic created in 4924 days ago, the information mentioned may be changed or developed.
    import os, errno

    def isExist(pid):
    try:
    os.kill(pid, 0)
    return True
    except OSError, e:
    if e.errno == errno.ESRCH:
    return False
    else
    return True

    http://linux.die.net/man/2/kill
    1,If sig is 0, then no signal is sent, but error checking is still performed; this can be used to check for the existence of a process ID or process group ID.
    2,ESRCH
    The pid or process group does not exist. Note that an existing process might be a zombie, a process which already committed termination, but has not yet been wait(2)ed for
    Supplement 1  ·  Apr 12, 2013
    主题中的代码格式乱的,贴个gist:https://gist.github.com/pdu/5368554/raw/d155ae790c502c99b6397e31a7fd55dc3ad88cff/isPidExist.py

    <script src="https://gist.github.com/pdu/5368554.js"></script>
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2317 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 10:01 · PVG 18:01 · LAX 03:01 · JFK 06:01
    ♥ Do have faith in what you're doing.