Solved

parallel forkmanager how do I know it forked

Posted on 2010-09-16
1
869 Views
Last Modified: 2012-08-13
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
Comment
Question by:warrior32
1 Comment
 
LVL 3

Accepted Solution

by:
gremwell earned 300 total points
ID: 33699083
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now