This got to long for a comment-
The wait
syscall (which os.wait
is a wrapper for) reaps exit codes/pids from dead processes. You will want to os.wait
in the process that is a generation above your zombie processes; the parent of the zombies processes. The parent processes will receive a SIGCHLD
signal when one of its child processes die. If you insist on doing all of this yourself, you will need to install a signal handler to trap for SIGCHLD
and in the signal handler call os.wait
. Read some documentation on unix process handling and the Python documentation on the os
module as there are variations of the os.wait
function that will be non-blocking which maybe helpful.
import signal
signal.signal(signal.SIGCHLD, lambda _x,_y: os.wait())