in reply to Re: Forks/Threads
in thread Forks/Threads

Thanks for the pointers! They helped a lot. So I've written a little test program to play with the forks and have included it below. Is there any problem with the way I'm keeping track of the max amount of forks to run at a given time? It seems to work fine but was wondering if there's something I'm not aware of or perhaps a better way.

my $max_children = 10; # max number of children my $num_children = 0; # number we have now foreach $item (@items) { if( my $p = fork() ) { if ($num_children >= $max_children) { $dead_child = wait; $num_children--; } $num_children++; # child count } else { #do some sort of child processing last; # We want out of the loop } }

Edit: 2001-03-03 by neshura