jplindstrom has asked for the wisdom of the Perl Monks concerning the following question:
Consider the following HTTP::Daemon code (simplified from my scenario), pretty much snipped from the synopsis, with forking added.
my $d = HTTP::Daemon->new( LocalPort => $self->port(), ReuseAddr => 1, ); $SIG{CLD} = $SIG{CHLD} = 'IGNORE'; while (my $c = $d->accept()) { next if(fork()); $SIG{CLD} = $SIG{CHLD} = 'DEFAULT'; #Reset child signal handler while (my $r = $c->get_request()) { # ... do stuff here, including a system() call } $c->close; undef($c); exit(0); }
At first, the fork left zombies. So I Googled for that, and figured I need a wait() or IGNORE handler. So I added that. The zombies went away.
But, instead I got problems with a system() call. It failed and $! was "No child processes". Huh?
My guess is that now it's the child signal handler that's messing this up, so I reset it to 'DEFAULT' after the fork. This seems to solve the problem and the system() works fine again.
Is this correct? Or did I just manage to fix the symptom instead of the problem?
/J
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Understanding fork + wait
by robartes (Priest) on Oct 29, 2002 at 13:35 UTC | |
Re: Understanding fork + wait
by VSarkiss (Monsignor) on Oct 29, 2002 at 16:10 UTC | |
by jplindstrom (Monsignor) on Oct 29, 2002 at 17:07 UTC | |
by agentv (Friar) on Oct 29, 2002 at 17:56 UTC |