because that would fork-bomb a machine if the array is large.

i did this in a previous script:

my $fork_num = ( $#hostlist <= MAXFORK ? $#hostlist : MAXFORK ); for ( 0..$fork_num ) { ## ## create bi-directional socket for parent/child communication my $to_child = IO::Socket->new(); my $to_parent = IO::Socket->new(); socketpair($to_child, $to_parent, PF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "Couldn't create socket pair: $!\n"; my $pid; if ( $pid = fork ) { ### parent process undef $to_parent; $to_child->autoflush; $children{$pid} = $to_child; sleep 1; next; } else { ### child process undef $to_child; undef %children; $to_parent->autoflush(1); local $SIG{PIPE} = sub { print " CAUGHT PIPE\n\n"; die "Signal caught in +Child $$: $!\n"; }; ## ## main processing occurs in the subroutine. &process_config_job($fork_num, $to_parent); } }

the child processes have a sub getnexthost() which asks the parent for another hostname.

the parent process has a subroutine to read the request for a new hostname then send it.

i don't like the 'fork foreach' idiom. good way to crash a box.


In reply to Re: Re: Using a stack with fork() by geektron
in thread Using a stack with fork() by mp3car-2001

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.