Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

parallel forkmanager how do I know it forked

Posted on 2010-09-16
1
Medium Priority
?
923 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 1200 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
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…
Six Sigma Control Plans

660 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