in reply to Re^2: Forking problem (manager)
in thread Forking problem UPDATED
after each child finishes there should be another one created
That's exactly what Parallel::ForkManager does.
Say you have 5 tasks, and you set a max of 3 children. ForkManager will create 3 children and assign them tasks 0, 1 and 2. When one of these end, another child is created for task 3. When one of child ends, another child is created for task 4. Having no more tasks to assign, it waits for the 3 children to end.
The implementation is very simple:
use Parallel::ForkManager qw( ) use constant MAX_PROCESSES => 3; my $pm = Parallel::ForkManager->new(MAX_PROCESSES); foreach $data (@array) { # Forks and returns the pid for the child: my $pid = $pm->start and next; ... do some work with $data in the child process ... $pm->finish; # Terminates the child process }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Forking problem (manager)
by avi_learns_perl (Novice) on Mar 07, 2007 at 09:26 UTC | |
by ikegami (Patriarch) on Mar 07, 2007 at 16:08 UTC | |
by tye (Sage) on Mar 07, 2007 at 17:35 UTC | |
by ikegami (Patriarch) on Mar 07, 2007 at 18:28 UTC | |
by avi_learns_perl (Novice) on Mar 08, 2007 at 11:57 UTC |