in reply to $SIG{INT} unlink problem
I just wanted to chime in with something else. Your code is assuming that fork() always succeeds (a dangerous assumption). Remember that it will return undef upon failure. A failure can be triggered by many events outside of your control, so you should be prepared to deal with them gracefully.
I offer you this substitute code instead:
Hope this helps,use strict; use warnings; use constant FORK_WAIT => 2; use constant MAX_ATTEMPTS => 10; our $attempt = 0; my $pid = undef; while (not defined ($pid = fork())) { die "Too many failed fork() attempts: $!\n" if ++$attempt > MAX_ATTEMPTS; warn "fork() failed: $!\n"; sleep $FORK_WAIT; } if ($pid) { # I'm the father } else { # I'm the son }
Edit: Thanks to wtp for the correction in the Perl's fork() behavior.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: $SIG{INT} unlink problem
by wtp (Initiate) on Aug 21, 2002 at 15:51 UTC | |
|
Re: Re: $SIG{INT} unlink problem
by agentv (Friar) on Aug 22, 2002 at 02:15 UTC |