I'm forking several child processes at once, and then "processing" them individually as they complete. I'd like for the "processing" subroutine to have some information about the child, in order to identify the child, but I don't know how to do this without globalizing my entire data structure

My first thought was to pass arguments to the reapChildren subroutine, but I get a "Not a subroutine reference"error

I then, tried:  sub {reapChildren($app)}, but  reapChildren was only getting the LAST app in the list.

Any help is greatly appreciated...even if there's a totally better way to do this. Thanks. Michele

Here's a snippet

:
use POSIX qw(:sys_wait_h :errno_h :signal_h); use strict; sub runChildren { my $obj = $_[0]; my $runlist = $obj->{'runlist'}; foreach my $app (@$runlist) { my $pid; if ($pid = fork) { $SIG{CHLD} = \&reapChildren; } else { my $appargs = $app->{'args'}; exec(@$appargs); } } } sub reapChildren { my $pid; $pid = waitpid(-1,&WNOHANG); if ($pid == -1 || WIFEXITED($?)) { processApplication; } $SIG{CHLD} = \&reapChildren; } sub processApplication { #Need to know which application needs processing }

In reply to Passing args to a subroutine reference by mjoyce

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.