Solved

parallel forkmanager how do I know it forked

Posted on 2010-09-16
1
883 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

777 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