I think you mean something like this:
#!/opt/perl/bin/perl -w use strict; my %kids; foreach my $letter ('x' .. 'z') { print localtime () . ": Forking kids for $letter\n"; foreach my $number (1 .. 5) { my $code = "$letter$number"; my $pid = fork; die "Failed to fork $code" unless defined $pid; $kids {$pid} = [$code, time] if $pid; unless ($pid) { # In child. my $sleep = 2 + int rand 18; print localtime () . ": Kid $code sleeping for $sleep seconds.\n"; sleep $sleep; exit; } } while ((my $kid = wait) != -1) { print localtime () . ": Reaped kid $kids{$kid}->[0] after ", time () - $kids {$kid} -> [1], " seconds.\n"; } print localtime () . ": Done reaping kids for $letter\n"; sleep 1; } __END__
Running this produces:
Tue Jun 26 19:40:41 2001: Forking kids for x
Tue Jun 26 19:40:42 2001: Kid x5 sleeping for 7 seconds.
Tue Jun 26 19:40:42 2001: Kid x2 sleeping for 9 seconds.
Tue Jun 26 19:40:42 2001: Kid x1 sleeping for 10 seconds.
Tue Jun 26 19:40:42 2001: Kid x3 sleeping for 11 seconds.
Tue Jun 26 19:40:42 2001: Kid x4 sleeping for 15 seconds.
Tue Jun 26 19:40:49 2001: Reaped kid x5 after 7 seconds.
Tue Jun 26 19:40:51 2001: Reaped kid x2 after 9 seconds.
Tue Jun 26 19:40:52 2001: Reaped kid x1 after 10 seconds.
Tue Jun 26 19:40:53 2001: Reaped kid x3 after 11 seconds.
Tue Jun 26 19:40:57 2001: Reaped kid x4 after 15 seconds.
Tue Jun 26 19:40:57 2001: Done reaping kids for x
Tue Jun 26 19:40:58 2001: Forking kids for y
Tue Jun 26 19:40:58 2001: Kid y4 sleeping for 4 seconds.
Tue Jun 26 19:40:58 2001: Kid y3 sleeping for 4 seconds.
Tue Jun 26 19:40:58 2001: Kid y5 sleeping for 7 seconds.
Tue Jun 26 19:40:58 2001: Kid y2 sleeping for 8 seconds.
Tue Jun 26 19:40:58 2001: Kid y1 sleeping for 10 seconds.
Tue Jun 26 19:41:02 2001: Reaped kid y4 after 4 seconds.
Tue Jun 26 19:41:02 2001: Reaped kid y3 after 4 seconds.
Tue Jun 26 19:41:05 2001: Reaped kid y5 after 7 seconds.
Tue Jun 26 19:41:06 2001: Reaped kid y2 after 8 seconds.
Tue Jun 26 19:41:08 2001: Reaped kid y1 after 10 seconds.
Tue Jun 26 19:41:08 2001: Done reaping kids for y
Tue Jun 26 19:41:09 2001: Forking kids for z
Tue Jun 26 19:41:09 2001: Kid z5 sleeping for 2 seconds.
Tue Jun 26 19:41:09 2001: Kid z2 sleeping for 5 seconds.
Tue Jun 26 19:41:09 2001: Kid z4 sleeping for 6 seconds.   
Tue Jun 26 19:41:09 2001: Kid z1 sleeping for 11 seconds.
Tue Jun 26 19:41:09 2001: Kid z3 sleeping for 12 seconds.
Tue Jun 26 19:41:11 2001: Reaped kid z5 after 2 seconds.
Tue Jun 26 19:41:14 2001: Reaped kid z2 after 5 seconds.
Tue Jun 26 19:41:15 2001: Reaped kid z4 after 6 seconds.
Tue Jun 26 19:41:20 2001: Reaped kid z1 after 11 seconds.
Tue Jun 26 19:41:21 2001: Reaped kid z3 after 12 seconds.
Tue Jun 26 19:41:21 2001: Done reaping kids for z

-- Abigail


In reply to Re: Fork novice requests help...Part Deux by Abigail
in thread Fork novice requests help...Part Deux by thor

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.