Note that this code will assume no other children will be spawned, and that $SIG {CHLD} hasn't been set to IGNORE
sub mfork ($$&) { my ($count, $max, $code) = @_; foreach my $c (1 .. $count) { wait unless $c <= $max; die "Fork failed: $!\n" unless defined (my $pid = fork); exit $code -> ($c) unless $pid; } 1 until -1 == wait; } sub afork (\@$&) { my ($data, $max, $code) = @_; my $c = 0; foreach my $data (@$data) { wait unless ++ $c <= $max; die "Fork failed: $!\n" unless defined (my $pid = fork); exit $code -> ($data) unless $pid; } 1 until -1 == wait; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Many children, but never more than a fixed number at once.
by gav^ (Curate) on Jun 20, 2002 at 03:05 UTC | |
by Abigail-II (Bishop) on Jul 08, 2002 at 16:33 UTC |