I looked at the docco on waitpid (at the perl and c lib level) and couldn't find any specification of what waitpid returned if (a) there was a child process (b) it wasn't defunct and (c) you specified WNOHANG.
Huh? from the waitpid section:
waitpid PID,FLAGS
Waits for a particular child process to terminate and returns the pid of the deceased process, or "-1" if there is no such child process. On some systems, a value of 0 indicates that there are processes still running. The status is returned in $?. If you say
use POSIX ":sys_wait_h";
#...
do {
$kid = waitpid(-1, WNOHANG);
} until $kid > 0;
then you can do a non-blocking wait for all pending zombie processes.
Emphasis mine. So, if you happen to be on a system where 0 indicates running processes, your test is wrong. It is also wrong to test for $kid == 0 as waitpid returns the pid of the deceased process. Again in your ordering:
- (a) waitpid returns the PID of the deceased process
- (b) waitpid returns 0 on some systems
- (c) WNOHANG means non-blocking waitpid (it should return if there's no PID immediately reported (hence the loop))
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
| [reply] [d/l] |