Solved

parallel forkmanager how do I know it forked

Posted on 2010-09-16
1
902 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Parse csv file and generate graphs in HTML in bash 8 301
XPath Syntax help in conjunction with perl XML::LibXML 18 144
Perl tar error 8 74
Perl script to process a .csv file 18 86
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

751 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