in reply to Re: Possible waitpid problem - pid reuse?
in thread Possible waitpid problem - pid reuse?
Not true. The program below forks, the child exits immediately. You will see that the signal handler is fired, but the child process stays around (as a zombie) until it's reaped by the waitpid call.
The signal handler fires three times in total: one for the child process, and once each for the calls to system.$SIG{CHLD} = sub {print("SIGCHLD\n")}; exit unless $pid = fork; sleep 1; system "ps -p $pid"; waitpid $pid, 0; system "ps -p $pid"; __END__ SIGCHLD PID TTY TIME CMD 29260 pts/32 00:00:00 perl <defunct> SIGCHLD PID TTY TIME CMD SIGCHLD
It's only when you explicitely set $SIG{CHLD} to IGNORE that child processes stay behind.
It's noteworthy to remember that POSIX does not specify what should happen if $SIG{CHLD} is ignored. (Which makes it a joy to program platform independently on Unix)
|
|---|