Portable way to tell if a process is still alive

Laszlo Nagy gandalf at shopzeus.com
Tue Dec 29 03:05:11 EST 2009


Suppose we have a program that writes its process id into a pid file. 
Usually the program deletes the pid file when it exists... But in some 
cases (for example, killed with kill -9 or TerminateProcess) pid file is 
left there. I would like to know if a process (given with its process 
id) is still running or not. I know that this can be done with OS 
specific calls. But that is not portable. It can also be done by 
executing "ps -p 23423" with subprocess module, but that is not portable 
either. Is there a portable way to do this?

If not, would it be a good idea to implement this (I think very 
primitive) function in the os module?

Thanks,

   Laszlo




More information about the Python-list mailing list