Hello Monks. I have spent days and days searching this site and everywhere trying to resolve this issue. I have a script that uses Parallel::ForkManager to fork off 3 concurrent processes. It loops through an array of 5 and the behavior I am looking for is to have three running all the time. The problem is if one of them hangs or is in a loop, the processing stops as wait_all_children is never satisfied. What I am looking for is to have the looping process do its thing (and I would add code to notify this is happening and, potentially, to automatically kill it) while allowing the other two available forks to continue processing. So, wait_all_children doesn't cut it. In my test script, below, I am forking 5 different scripts. Scripts test[1235].sh just echo "I am running testx.sh" while test4.sh echoes the same in an endless loop with a sleep 10 in it. It all stops and leaves just test4.sh running indefinitely and, since wait_all_children isn't satisfied, the others are never forked off again.
use strict; use warnings; use Parallel::ForkManager; my @runArray = ("test1.sh", "test2.sh", "test3.sh", "test4.sh", "test5 +.sh"); my ($pid, $exitCode, $ident); my $forkMgr = Parallel::ForkManager->new(3); $forkMgr->run_on_start( sub { ($pid, $ident) = @_; print "Started ==> $ident\n"; } ); $forkMgr->run_on_finish( sub { ($pid, $exitCode, $ident) = @_; print "Ended ==> $ident\n"; } ); while (1) { for my $runCommand (@runArray) { $forkMgr->start($runCommand) and next; system("/usr/localcw/opt/patrol/nagios/libexec/$runCommand"); $forkMgr->finish; } $forkMgr->wait_all_children; sleep 10; } exit;
Even commenting out wait_all_children doesn't help. This is a sample from a critical application I am working on and I am at wit's end. Thanks for your consideration, Rick

In reply to Parallel::ForkManager and wait_all_children by rgren925

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.