Thanks for the pointers to POE and xargs.  Unfortunately I&#39;m restricted to using Perl core modules (and probably back to Perl 5.001 from 1995).<br><br>DaveB wrote:<br>&gt; I would think &quot;wait&quot; (rather than &quot;waitpid&quot;) should fit the bill, as
&quot;wait&quot; <br>&gt; should return the PID of whatever child exited most recently,
right?<br><br>*slaps forehead* <br><br>So, after a few minutes of re-reading the wait() manpage and some hacking, here&#39;s a script that demonstrates what I was looking for:<br>##### begin #####<br>#!/usr/bin/perl<br>use strict;<br>

my @array = qw(AA BB CC DD EE FF GG);<br>my $sleep = 10;<br>my %children;<br><br>for my $A (0..scalar(@array)-1) {<br>        my $pid = fork();<br>        if ($pid) {<br>                # parent<br>                $children{$pid}=@array[$A];<br>

        } elsif ($pid == 0) {<br>                # child<br>                my $X = $sleep*rand();<br>                my $now = localtime();<br>                printf &quot;$now Executing %s for %5.3f seconds.\n&quot;,@array[$A],$X;<br>

                sleep $X;<br>                exit(0);<br>        } else {<br>                die &quot;couldn&#39;t fork: $!\n&quot;;<br>        }<br>}<br><br>my $exited;<br>while (($exited = wait()) &amp;&amp; ($exited &gt; 0 )) {<br>

        my $now = localtime();<br>        printf &quot;$now EXITED: $exited(%s)&quot;, $children{$exited};<br>        delete $children{$exited};<br>        if (scalar %children &gt; 0 ) {<br>                printf &quot;, waiting for&quot;;<br>

                foreach my $B (sort keys(%children)) {<br>                        printf &quot;: %5i(%s) &quot;,$B, $children{$B};<br>                }<br>        }<br>        printf &quot;\n&quot;;<br>}<br>##### end #####<br>

<br>And here&#39;s some output (YMMV due to the rand() call):<br>$ perl A0006.pl<br>Mon Apr 20 22:36:25 2009 Executing AA for 0.356 seconds.<br>Mon Apr 20 22:36:25 2009 Executing BB for 9.797 seconds.<br>Mon Apr 20 22:36:25 2009 Executing CC for 4.411 seconds.<br>

Mon Apr 20 22:36:25 2009 Executing DD for 7.816 seconds.<br>Mon Apr 20 22:36:25 2009 Executing EE for 5.170 seconds.<br>Mon Apr 20 22:36:25 2009 Executing FF for 8.632 seconds.<br>Mon Apr 20 22:36:25 2009 Executing GG for 6.502 seconds.<br>

Mon Apr 20 22:36:25 2009 EXITED: 12343(AA), waiting for: 12344(BB) : 12345(CC) : 12346(DD) : 12347(EE) : 12348(FF) : 12349(GG)<br>Mon Apr 20 22:36:29 2009 EXITED: 12345(CC), waiting for: 12344(BB) : 12346(DD) : 12347(EE) : 12348(FF) : 12349(GG)<br>

Mon Apr 20 22:36:30 2009 EXITED: 12347(EE), waiting for: 12344(BB) : 12346(DD) : 12348(FF) : 12349(GG)<br>Mon Apr 20 22:36:31 2009 EXITED: 12349(GG), waiting for: 12344(BB) : 12346(DD) : 12348(FF)<br>Mon Apr 20 22:36:32 2009 EXITED: 12346(DD), waiting for: 12344(BB) : 12348(FF)<br>

Mon Apr 20 22:36:33 2009 EXITED: 12348(FF), waiting for: 12344(BB)<br>Mon Apr 20 22:36:34 2009 EXITED: 12344(BB)<br><br>Thanks for the kick in the pants to re-read the wait() function. :-)<br><br>Dan<br><br clear="all">&quot;Quis custodiet ipsos custodes?&quot; (Who can watch the watchmen?) -- from the Satires of Juvenal<br>

&quot;I do not fear computers, I fear the lack of them.&quot; -- Isaac Asimov (Author)<br>** *** ***** ******* *********** *************<br>
<br><br><div class="gmail_quote">On Mon, Apr 20, 2009 at 21:16, George Neill <span dir="ltr">&lt;<a href="mailto:georgen@neillnet.com">georgen@neillnet.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div class="im">On Mon, Apr 20, 2009 at 7:42 PM, Jay Hannah &lt;<a href="mailto:jay@jays.net">jay@jays.net</a>&gt; wrote:<br>
&gt; On Apr 19, 2009, at 5:42 PM, Dan Linder wrote:<br>
&gt;&gt;<br>
&gt;&gt; I&#39;ve tried using &quot;waitpid(-1,WNOHANG)&quot; thinking that would return the PID<br>
&gt;&gt; of the last child to die, or &quot;-1&quot; if none had died since last checking, but<br>
&gt;&gt; that seems to just hang _waiting_ for the next death to happen...   I did a<br>
&gt;&gt; &quot;waitpid($pid_of_a_child, 0)&quot; but tha just waits until that specific child<br>
&gt;&gt; dies.<br>
&gt;&gt;<br>
&gt;&gt; Anyone have any example code that can do this?<br>
&gt;<br>
&gt; We use POE for things like this. Specifically, this cookbook recipe:<br>
&gt;<br>
&gt; <a href="http://poe.perl.org/?POE_Cookbook/Child_Processes_3" target="_blank">http://poe.perl.org/?POE_Cookbook/Child_Processes_3</a><br>
&gt;<br>
&gt; There&#39;s a pretty active IRC channel that can help if you get stuck<br>
&gt; (<a href="http://irc.perl.org" target="_blank">irc.perl.org</a> #poe). I&#39;m sure there&#39;s mailing lists too.<br>
&gt;<br>
&gt; I got somebody started from scratch last week and he seemed to take to it<br>
&gt; pretty quickly.<br>
<br>
</div>POE looks pretty nifty Jay.<br>
<br>
If you want to be lazy (like me), here&#39;s a simple/quick xargs example<br>
to demonstrate how one could tackle the problem,<br>
<br>
gneill@blackfoot:~$ cat test.input<br>
10<br>
9<br>
8<br>
7<br>
6<br>
5<br>
4<br>
3<br>
2<br>
1<br>
<br>
cat test.input | xargs --max-procs=4 --replace=timeout perl -e &#39;print<br>
&quot;starting timeout\n&quot;; sleep(timeout); print &quot;finished timeout\n&quot;;&#39;<br>
<br>
running 4 ways parallel,<br>
<br>
gneill@blackfoot:~$ time cat test.input | xargs --max-procs=4<br>
--replace=timeout perl -e &#39;print &quot;starting timeout\n&quot;; sleep(timeout);<br>
print &quot;finished timeout\n&quot;;&#39;<br>
starting 10<br>
starting 9<br>
starting 8<br>
starting 7<br>
finished 7<br>
starting 6<br>
finished 8<br>
starting 5<br>
finished 9<br>
starting 4<br>
finished 10<br>
starting 3<br>
finished 3<br>
starting 2<br>
finished 4<br>
starting 1<br>
finished 5<br>
finished 6<br>
finished 1<br>
finished 2<br>
<br>
real    0m15.034s<br>
user    0m0.048s<br>
sys     0m0.016s<br>
<br>
<br>
running serial (aka, no --max-procs)<br>
<br>
gneill@blackfoot:~$ time cat test.input | xargs --replace=timeout perl<br>
-e &#39;print &quot;starting timeout\n&quot;; sleep(timeout); print &quot;finished<br>
timeout\n&quot;;&#39;<br>
starting 10<br>
finished 10<br>
starting 9<br>
finished 9<br>
starting 8<br>
finished 8<br>
starting 7<br>
finished 7<br>
starting 6<br>
finished 6<br>
starting 5<br>
finished 5<br>
starting 4<br>
finished 4<br>
starting 3<br>
finished 3<br>
starting 2<br>
finished 2<br>
starting 1<br>
finished 1<br>
<br>
real    0m55.087s<br>
user    0m0.036s<br>
sys     0m0.016s<br>
<br>
Later,<br>
<font color="#888888">George<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Omaha-pm mailing list<br>
<a href="mailto:Omaha-pm@pm.org">Omaha-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/omaha-pm" target="_blank">http://mail.pm.org/mailman/listinfo/omaha-pm</a></div></div></blockquote></div><br>