Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 933
  • Last Modified:

parallel forkmanager how do I know it forked

I'm using the parallel forkmanager in Perl, when I do
my $pid = $pm->start and next;

the value of $pid is 0 and when I use top or ps to see the processes running I only see one perl process executing. How do I know for sure it did fork all threads specified (3 from my code) Below is my code.

my $start_time = time;
my $pm = new Parallel::ForkManager(3);

#run for 10 seconds
while(time - $start_time<=10){

  my $pid = $pm->start and next;
  print "pid = $pid\n";

   my $ranID = getRandomID(@IDS);

   system("php test.php $ID $ranID");
   $pm->finish;
}
0
warrior32
Asked:
warrior32
1 Solution
 
gremwellCommented:
If you see one process executing, it must be parent. Perhaps your child processes die off very fast for one or another reason. Consider replacing system() call with sleep(5) and trying again.

You can track new children as they get spawned by overriding run_on_start() callback. See the examples in perldoc of Parallel::FormManager module http://search.cpan.org/~dlux/Parallel-ForkManager-0.7.6/ForkManager.pm . In the code of the callback you can increment some counter. I doubt if it is really what you need though, see also below.

In general, you can be sure that necessary number of sub-processes get started. In fact start() function will block until it succeeds to spawn a child process. Note that you after you have done all your start()'s, you may wait for the children to finish. This can be accomplished by invoking $pm->wait_all_children();
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now