in reply to Re: Communicate with child process via stdin, stdout
in thread Communicate with child process via stdin, stdout

waitpid($pid, 1); # It is important to waitpid on your child process, # otherwise zombies could be created.

As an aside, waitpid at the end of a script (as you have it here) is not important or necessary. Nothing bad will happen without it, as the OS will automatically reap any zombies when their parent process has gone away. In other words, zombies can only exist as long as the parent is still alive.

Replies are listed 'Best First'.
Re^3: Communicate with child process via stdin, stdout
by locked_user sundialsvc4 (Abbot) on Nov 20, 2011 at 13:52 UTC

    Dunno...   I have encountered zombies with a parent-PID of “1.”   Dunno why it happens and I don’t think it should, but, “there they were.”   I have only seen it in a FastCGI process (owned by Plack), but I have seen it nonetheless.   It probably is a good idea, then, to clean up after oneself explicitly.   If you rendezvous with every child-process that you created, and show them to their graves, then everything is nice and neat and predictable.

      The OS re-parents a process to the init process (PID 1) when a child process is still running at the time the parent has gone away. This is entirely different from the situation above, because when you're dead you yourself can no longer wait for your children anyway.