I have a process id in Python. I know I can kill it with os.kill(), but how do I check if it is alive ? Is there a built-in function or do I have to go to the shell?
+7
A:
Use subprocess module to spawn process. There is proc.poll() - function it returns Null if process is still alive otherwise it returns process returncode.
Mihail
2009-07-11 18:19:24
+7
A:
os.kill
does not kill processes, it sends them signals (it's poorly named).
If you send signal 0, you can determine whether you are allowed to send other signals. An error code will indicate whether it's a permission problem or a missing process.
See man 2 kill
for more info.
Also, if the process is your child, you can get a SIGCHLD
when it dies, and you can use one of the wait
calls to deal with it.
Dustin
2009-07-11 19:12:22