What is the difference between these settings?
$SIG{CHLD} = 'IGNORE' $SIG{CHLD} = 'DEFAULT' $SIG{CHLD} = '' $SIG{CHLD} = undef
According to the "Advanced Programming on UNIX, Second Edition" in Figure 10.1, the default value of SIGCHLD is "ignored."
If "ignore" means "SIG_IGN", then no child will ever become a zombie, and it is not.
From there it does not become clearer:
If a process specifically sets its location to SIG_IGN, the children of the calling process will not generate zombie processes. Note that this is different from the default action (SIG_DFL), which should be ignored from Figure 10.1. Instead, upon completion, the status of these child processes is discarded.
I find it difficult to understand how various values ββ(or undefined non-value) affect. So far, the solution has been to rotate these options until I get the desired behavior, and I would better understand how each value determines the behavior of the signal.
Behavior: the child process calls the "system" or uses inverse elements that create another child, and the signal usually falls on the wrong (parent) handler. Installing a local handler may work, but I donβt understand which value is most appropriate if I want the signal from grand-child to do nothing.
Can someone please light me up?
UPDATE: Based on ikegami feedback, I did some specific tests. The behavior, at least in part, is platform dependent.
Consider the following snippet:
$SIG{CHLD} = sub { while( ( my $child = waitpid( -1, &WNOHANG ) ) > 0 ) { print "SIGNAL CHLD $child\n"; } }; my $pid = fork(); if( ! $pid ) { system( 'echo Grandchild PID = $$' ); sleep 2; exit; } print "Child PID = $pid\n"; sleep 5;
Perl 5.8.6 on Solaris 10 will display "SIGNAL CHLD" messages for the PID call to system (). Doing everything, even as trivial as
local $ SIG {CHLD};
in the child will suppress these messages.
On every other taste that I tried, the reaper never sees a child.