Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
Once again I call on your help because I obviously don't really understand forking yet, although I have been reading up :-/
In the script below, there is something I want to do after sending off the children within the loop. But for some reason, everything after $fork_manager->finish never happens, and I don't understand why. I thought maybe the problem was the "... and next" at the start of the fork, because I've had problems with that in subs before. However, at the time, I enclosed the block in an extra {...}, and it worked. That doesn't help here.
use strict; use warnings; use diagnostics -verbose; use Parallel::ForkManager; my @array = ("") x 56; my $fork_manager = new Parallel::ForkManager(16); my $check = 0; for my $val (@array) { $fork_manager->start and next; $check++; $fork_manager->finish; # Terminates the child process print "Hello?\n"; # $fork_manager->start and next; # $check++; # $fork_manager->finish; } print "End: " . $check . "\n";
In addition, what I want to do relies on the processes within that iteration of the loop being done. I thought of using $fork_manager->wait_all_children, but doesn't that mean that ALL processes must be done, e.g. I could use it only outside the loop?
And then finally, there is one thing I am not sure about Fork::Manager's documentation: What if after the 1st bunch of processes in the loop, I want to start so more? Can I use the same object or should I create a new one? The documentation does contain a note about managing a set of subprocesses within the 1st one, but that's different from what I want to do here (I think).
I would gladly be enlightened :-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with [mod://Fork::Manager]
by RichardK (Parson) on May 30, 2012 at 08:50 UTC | |
by Anonymous Monk on May 30, 2012 at 12:41 UTC | |
by Anonymous Monk on May 31, 2012 at 09:22 UTC | |
|
Re: Problem with [mod://Fork::Manager]
by locked_user sundialsvc4 (Abbot) on May 30, 2012 at 14:40 UTC | |
by Anonymous Monk on May 30, 2012 at 14:53 UTC |