I know you're using P::FM. However, I have to wonder if this would be easier to do with AnyEvent. I'm not entirely sure, as after about 10 minutes, I still don't have example code quite working :-) but maybe it's something to start with.

use 5.14.0; use EV; use AnyEvent; use AnyEvent::Util qw(run_cmd); use File::Spec; # set up my condvars my $all_done = AE::cv; $all_done->begin for 1..50; my $ten = AE::cv; # start the first 10... start_ten($ten, $all_done, $_) for 1..2; # wait for all of them to finish. $all_done->recv(); sub start_ten { my $t = shift; my $all = shift; my $one = shift; state $started = 0; # 10/100 too much for my machine... for (1..5) { $started ++; my $proc = $started; $t->begin if $one == 1; $all->end; print "Starting...$proc\n"; my $cv = run_cmd( ['sleep', rand(3)], '>' => File::Spec->devnull(), '2>' => File::Spec->devnull(), '<' => File::Spec->devnull(), ); $cv->cb( sub { my $c = shift; my $rc = $c->recv(); print "Finished $proc: $rc\n"; $t->end() }); } # when we're done, start the next ten. $t->cb( sub { my $c = shift; print "Checking next group...($started)\n"; $c->recv; $all->ready() or start_ten($t, $all, 1) }); }
There is some tweaking required - this will start the first two groups of five, and wait - once the first five come in, it goes and starts the rest. It's not waiting properly. There is also AnyEvent::Util::fork_call which is quite similar to what you want to do, and you may be able to adapt its methods to what you want to do while still leaving much of the heavy lifting to AnyEvent.

Note that 100 processes being kicked off can do serious damage to your system's responsiveness. Hopefully you have the requisite CPU/RAM :-)


In reply to Re: Parallel::ForkManager How to wait when 1st 10 Child processe are over out of 100 by Tanktalus
in thread Parallel::ForkManager How to wait when 1st 10 Child processe are over out of 100 by anshumangoyal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.