best way to check if pid is dead?

Roy Smith roy at panix.com
Wed May 21 15:13:18 EDT 2008


In article 
<90ecca29-c4d8-4e89-908a-93850d7de1bf at i76g2000hsf.googlegroups.com>,
 bukzor <workitharder at gmail.com> wrote:

> Does anyone have a pythonic way to check if a process is dead, given
> the pid?
> 
> This is the function I'm using is quite OS dependent. A good candidate
> might be "try: kill(pid)", since it throws an exception if the pid is
> dead, but that sends a signal which might interfere with the process.
> 
> Thanks.
> --Buck

The canonical way is to do kill(pid, 0).  If it doesn't throw, the process 
exists.  No actual signal is sent to the process either way.

Of course, the process could exit immediately after the kill() call, so by 
the time you find out it's alive, it's dead.  Such is life.



More information about the Python-list mailing list