As your output shows, the same process is handling all the tasks. That's because the parent is forking a child but then continuing the work itself.

You are missing the statement that causes the parent to skip out of the loop. See the doc for Parallel::ForkManager, which states (emphasis added):

The following example shows the difference:

use strict; use warnings; use feature 'say'; use Parallel::ForkManager; use Time::HiRes qw/ time /; $|++; my $forker = Parallel::ForkManager->new(4); say "v.1"; for ( 0 .. 9 ) { my $pid = $forker->start; if ( $pid ) { say "1 $$ $_ start: " . time; sleep 1; } $forker->finish; } my $forker2 = Parallel::ForkManager->new(4); say "v.2"; for ( 0 .. 9 ) { my $pid = $forker->start and next; say "2 $$ $_ start: " . time; sleep 1; $forker->finish; } __END__
Output:
$ perl 1187274.pl v.1 1 19015 0 start: 1491486225.44169 1 19015 1 start: 1491486226.44244 1 19015 2 start: 1491486227.44318 1 19015 3 start: 1491486228.44402 1 19015 4 start: 1491486229.44495 1 19015 5 start: 1491486230.44586 1 19015 6 start: 1491486231.447 1 19015 7 start: 1491486232.44791 1 19015 8 start: 1491486233.44877 1 19015 9 start: 1491486234.4497 v.2 2 19026 0 start: 1491486235.45079 2 19027 1 start: 1491486235.45113 2 19028 2 start: 1491486235.45138 2 19029 3 start: 1491486235.4517 2 19030 4 start: 1491486237.45457 2 19031 5 start: 1491486237.45492 2 19032 6 start: 1491486237.45516 2 19033 7 start: 1491486237.45543 2 19035 9 start: 1491486239.45953 2 19034 8 start: 1491486239.45992

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re^3: Parallel::Forkmanager question by 1nickt
in thread Parallel::Forkmanager question by jamesgerard1964

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.