V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2013-04-11 22:22:53 +08:00 · 4208 次点击
    这是一个创建于 4226 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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
    第 1 条附言  ·  2013-04-12 09:24:23 +08:00
    主题中的代码格式乱的,贴个gist:https://gist.github.com/pdu/5368554/raw/d155ae790c502c99b6397e31a7fd55dc3ad88cff/isPidExist.py

    <script src="https://gist.github.com/pdu/5368554.js"></script>
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5504 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 05:48 · PVG 13:48 · LAX 21:48 · JFK 00:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.