The solution to this I found online was:
However, it fails if the process is a zombie. This is a much better solution if the process is a child:
import os, errno
def PidIsAlive(pid):
try:
os.kill(pid, 0)
return True
except OSError, e:
return e.errno == errno.EPERM
However, it fails if the process is a zombie. This is a much better solution if the process is a child:
import os, errnoGranted, this is exposed through subprocess.Popen.poll(). However, poll() doesn't allow you to check on child processes of the Popen object.
def PidIsAlive(pid):
try:
return os.waitpid(pid, os.WNOHANG) == (0, 0)
except OSError, e:
if e.errno != errno.ECHILD:
raise