xiper has asked for the wisdom of the Perl Monks concerning the following question:
My code so far, if anyone's interested:
my( %pid ); foreach my $num ( "01" .. "25" ) { # if max processes, wait for one to finish if( keys( %pid ) >= 10 ) { &reap() } if( my $pid = fork() ) # parent { $pid{$pid} = $num; } else # child { &child( $num ); exit 0; } } # reap remaining processes while( %pid ) { &reap() } # <collect data> sub reap { my( $pid ) = wait(); if( $pid == -1 ) { die( "no more kids to reap!\n" ) } if(! $pid{$pid} ) { die( "why did I see $pid?\n" ) } delete( $pid{$pid} ); } sub child { my( $num ) = $_[0]; print "child $num spawned\n"; # <send data> }
Thanks all!
- ><iper
my JAPH: print"Just another Perl hacker\n"; # ^ look, no space! pretty tricky huh?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Receiving data from many children
by Zaxo (Archbishop) on Aug 20, 2003 at 03:09 UTC | |
by xiper (Friar) on Aug 20, 2003 at 04:21 UTC | |
|
•Re: Receiving data from many children
by merlyn (Sage) on Aug 20, 2003 at 03:16 UTC | |
|
Re: Receiving data from many children
by Flame (Deacon) on Aug 20, 2003 at 16:06 UTC | |
|
Re: Receiving data from many children
by NetWallah (Canon) on Aug 21, 2003 at 00:02 UTC |