I am having a problem with the www.cpan.org module Proc::Queue

Proc::Queue is successfully capping the maximum number of active child processes my program can have at 5, using the following code:

use Proc::Queue size => 5, debug => 1; use POSIX ":sys_wait_h"; # imports WNOHANG foreach (1..20) { my $f=fork; (my child processes do stuff) exit 0; # stop a child process 1 while waitpid(-1, WNOHANG)>0; # reaps children }
My problem is, I have several functions in my Perl script that used forked processes, and I need to use Proc::Queue in each of these functions to cap the maximum number of active forked processes allowed.

However, I am finding that even before an earlier function in my main completes all its child processes, the next function called by my main starts, and begins to make forked processes of its own.

Is there a way to insure that a given function that uses fork() and Proc::Queue reaps all of its child processes, before execution of the script returns to main and starts the next function call in main?

The functions called in my Perl script's main have dependencies such that a given function MUST be 100% done with its activities, before the next function in main is called.

Thank You,
Amphiaraus

In reply to Proc::Queue problem by Amphiaraus

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.