dkode has asked for the wisdom of the Perl Monks concerning the following question:
When i try out this program it seems like none of the children are exiting at all...Any ideas on why it would be doing so? I'm quite confused and finally found Parallel::ForkManger, does anyone have comments on it or have better modules to use when playing with fork()? I appreciate your time fellow monks.use strict; use Parallel::ForkManager; print "Content-Type: text/html\n\n"; my $max_procs = 5; my @names = qw( Fred Jim Lily Steve ); # hash to resolve PID's back to child specific information my $pm = new Parallel::ForkManager($max_procs); # Setup a callback for when a child finishes up so we can # get it's exit code $pm->on_finish( sub { my ($pid, $exit_code, $ident) = @_; print "** $ident just got out of the pool <br>". "with PID $pid and exit code: $exit_code<br>\n"; } ); $pm->on_start( sub { my ($pid,$ident)=@_; print "** $ident started, pid: $pid<br>\n"; } ); $pm->on_wait( sub { print "** Have to wait for one children ...<br>\n" } ); foreach my $child (0 .. $#names ) { my $pid = $pm->start($names[$child]) and next; # This code is the child process print "This is $names[$child], Child number $child<br>\n"; # sleep ( 2 * $child ); print "$names[$child], Child $child is about to get out...<br>\n"; sleep 1; # pass an exit code to finish $pm->finish($child); } print "Waiting for Children...<br>\n"; $pm->wait_all_childs; print "Everybody is out of the pool!<br>\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: Fork() confusion
by tilly (Archbishop) on May 29, 2001 at 07:25 UTC | |
by dkode (Acolyte) on May 29, 2001 at 08:18 UTC | |
by tilly (Archbishop) on May 29, 2001 at 08:37 UTC |