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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.