in reply to exec creating zombie processes

The problem is, when there is a timeout, your parent process is waiting. Since you interrupt the wait, the zombie is never reaped.

Instead of adding another wait, why not just set $SIG{CHLD} = 'IGNORE';?

Replies are listed 'Best First'.
Re^2: exec creating zombie processes
by ikegami (Patriarch) on Feb 14, 2011 at 22:05 UTC

    Cause it complicates things. First, that wouldn't work. You'd have to change the existing waitpid to sleep. You'd end up with:

    { local $SIG{CHLD} = 'IGNORE'; ... launch child ... if (sleep(20)) { kill(KILL => $child_pid); # Wait for child to die before restoring $SIG{CHLD}. # Unlikely race condition. while (kill(0, $child_pid)) { sleep(1) or last; } } }

    There are side-effects to using $SIG{CHLD} = 'IGNORE'.

    • One can't know the exit code of one's children,
    • one can't use system, backticks, open '-|' or open '|-', and
    • one needs to worry about EINTR.