How to check if a process is alive in Python on Linux?

I have a process id in Python. I know I can kill him with os.kill (), but how do I check if he is alive? Is there a built-in function or do I need to go into a shell?

+3
source share
2 answers

Use the subprocessmodule to start the process. There is a function proc.poll () - it returns Noneif the process is still alive, otherwise it returns a return code for the process.

http://docs.python.org/library/subprocess.html

+17
source

os.kill does not kill processes, it sends them signals (it is poorly named).

0, , . , .

. man 2 kill.

, , SIGCHLD, , wait, .

+14

Source: https://habr.com/ru/post/1712386/


All Articles