|Syntactic Confectionery Delight|
Re^2: confusing fork/readline behaviour (wait)by tye (Sage)
|on Aug 14, 2015 at 14:18 UTC||Need Help??|
In addition, parents should wait for children before exiting
Yes, that is a good general practice. The most common problem of not doing that is that the shell that launched the command waits for the parent to exit, then displays the next prompt, then the child outputs a bit more, making a confusing display. Things get worse if a child might be reading from the same STDIN. And even if the parent process wasn't launched as a command from an interactive shell, it is often good to not have the parent exit before the children; for example, you often don't want to restart some service or daemon when some children from the last instance are still hanging around.
otherwise children either get killed or stop running and become zombie processes
But neither of those are valid justifications for that practice.
The parent exiting doesn't kill the child. The closest thing to that is that the login process exiting will send SIGHUP to all processes that share that controlling tty. (And your Perl script is pretty darn unlikely to be a login process.)
When a child process exits, it becomes a zombie process until its parent waits for it, or until the parent process exits (because then the child gets inherited by process 1 which scrupulously wait()s for any expired children). So preventing zombies is a good reason to wait() for children, but the one time that it doesn't matter is right before the parent process exits.