Hello,

Once again I call on your help because I obviously don't really understand forking yet, although I have been reading up :-/

In the script below, there is something I want to do after sending off the children within the loop. But for some reason, everything after $fork_manager->finish never happens, and I don't understand why. I thought maybe the problem was the "... and next" at the start of the fork, because I've had problems with that in subs before. However, at the time, I enclosed the block in an extra {...}, and it worked. That doesn't help here.

use strict; use warnings; use diagnostics -verbose; use Parallel::ForkManager; my @array = ("") x 56; my $fork_manager = new Parallel::ForkManager(16); my $check = 0; for my $val (@array) { $fork_manager->start and next; $check++; $fork_manager->finish; # Terminates the child process print "Hello?\n"; # $fork_manager->start and next; # $check++; # $fork_manager->finish; } print "End: " . $check . "\n";

In addition, what I want to do relies on the processes within that iteration of the loop being done. I thought of using $fork_manager->wait_all_children, but doesn't that mean that ALL processes must be done, e.g. I could use it only outside the loop?

And then finally, there is one thing I am not sure about Fork::Manager's documentation: What if after the 1st bunch of processes in the loop, I want to start so more? Can I use the same object or should I create a new one? The documentation does contain a note about managing a set of subprocesses within the 1st one, but that's different from what I want to do here (I think).

I would gladly be enlightened :-)


In reply to Problem with [mod://Fork::Manager] by Anonymous Monk

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.