On 5/15/06, Tom Allison <[EMAIL PROTECTED]> wrote:
my $pid = fork(); print "$pid --> $file\n";
Because your process table can become full and temporarily prevent forking new processes, you should check the return value of fork whenever you're making more than N processes. The value of N depends upon a number of factors, so I generally assume N=0. Most of the time, I just call this safe_fork routine in place of fork, since this handles the retries for me automatically. sub safe_fork () { use Errno; my $retries = 10; while ($retries--) { my $rv = fork; return $rv if defined $rv; # it worked return unless $retries; return unless $!{EAGAIN}; sleep 3; } die "Well, how did I get here?"; }
I will get an output of: 0 --> file_one 3242 --> file_one 0--> file_two but no 3243-->file_two.
If that output is coming from several concurrent processes, any one process's output can "interrupt" another: The data may be interleaved in confusing ways. But maybe you simply couldn't fork another process? How many processes were you starting at once?
Unfortunately, perl -d doesn't work well for forks.
There's actually some support for fork in the debugger, but I'm having a hard time finding any documentation on it, other than the comments. Search for 'fork' in your perl5db.pl file, if you need it. Good luck with it! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>