According to the late
W. Richard Stevens, arguably the foremost authority on UNIX programming and teaching until his sudden death in 1999, wait() should not be used in any new programming. wait() is an old function dating back to the early days of SysV. The problem with wait() is that it allows zombie processes to come around- and quite easily, may I add. Wait() blocks until a child exits. If you have multiple children, you are supposed to wait() after catching SIGCHLD until all children have been dismissed. But during this loop effect, since most people/ vendors ignore the new POSIX sigqueue() function, UNIX signals are not queued and thus a child can become a zombie while storing the returned result resetting wait(). What's worse is that this problem is nondeterministic, meaning that every time you run the program, you are unlikely to get similar results- this leads, of course, to code that is impossible to debug. The solution cannot be found with some trick with wait()- instead one must default to waitpid(). One must call waitpid() in a loop when you catch the SIGCHLD. Furthermore, waitpid() allows a WNOHANG flag which will allow your program to continue and not block forever if you have no more children. Thus, all children are caught- no zombies. Quoting from his famous "UNIX Network Programming- Vol. I", "...we cannot call wait in a loop, because there is no way to prevent wait from blocking if there exist running children that have not yet terminated." and "Establishing a signal handler and calling wait from that handler is insufficient for preventing zombies...The correct solution is to call waitpid instead of wait." (p. 127) In Perl, this is especially dangerous, since what you may see as one function call, may be actually multiple C functions and even several uninterruptible kernel calls. An interruption (signal catch) there can be especially bad. So the only solution is waitpid(). Thanks for the --, though. Hope this helps.