G
gaurava
Hi,
I am trying to write a program where the main process registers a
SIGNAL handler for SIGCHLD, forks a bunch of processes and then reaps
the dead children. I have some control over when to register the
signal handler (before or after forking the child processes but not a
whole lot). I am seeing some weird behaviour. Basically I see a valid
child exit, handle it, and then start seeing a slew of SIGCHLD signals
from a process with PID 0. I was wondering if someone could tell me
the right way to handle signals, or has seen this problem before and
knows how to fix it. I am copying pseudo code for my script below.
Thanks,
Gaurav
sub handler {
while(($kid = waitpid(-1, WNOHANG)) != -1) {
if ($kid == $imp_pid) {
exit();
}
}
}
$imp_pid = fork_important_child();
$SIG{CHLD} = 'handler;
$other_pid = fork_normal_process();
$yet_another_pid = fork_normal_process();
:
:
snip
I am trying to write a program where the main process registers a
SIGNAL handler for SIGCHLD, forks a bunch of processes and then reaps
the dead children. I have some control over when to register the
signal handler (before or after forking the child processes but not a
whole lot). I am seeing some weird behaviour. Basically I see a valid
child exit, handle it, and then start seeing a slew of SIGCHLD signals
from a process with PID 0. I was wondering if someone could tell me
the right way to handle signals, or has seen this problem before and
knows how to fix it. I am copying pseudo code for my script below.
Thanks,
Gaurav
sub handler {
while(($kid = waitpid(-1, WNOHANG)) != -1) {
if ($kid == $imp_pid) {
exit();
}
}
}
$imp_pid = fork_important_child();
$SIG{CHLD} = 'handler;
$other_pid = fork_normal_process();
$yet_another_pid = fork_normal_process();
:
:
snip