crackotter has asked for the wisdom of the Perl Monks concerning the following question:
How do I get the return values of the Subfunction I fork off?? In the $pfm->run_on_finish section??#!/usr/bin/perl #Script to test out the Parallel::ForkManager module use strict; use Parallel::ForkManager; %Test_hash=("A",1,"B",2,"C",3,"D",4); #Start the Parrel Fork Manager my $pfm = new Parallel::ForkManager($max_threads); # Setup a callback for when a child finishes up so we can # get it's exit code $pfm->run_on_finish( sub { my ($pid, $exit_code, $ident) = @_; print $pid . "\n"; # print "** $ident just got out of the pool ". # "with PID $pid and exit code: $exit_code\n"; } ); my $line=""; my $child=""; my %Values=(); foreach $line(keys %Test_hash) { # Forks and returns the pid for the child: my $pid = $pfm->start($line) and next; $Values{$pid}=&Test_fork($line, $Test_hash{$line}); $pfm->finish($child); # Terminates the child proces } sub Test_function { my ($a,$b)=@_ my $c = $a * $b; return $c; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parallel::ForkManager question
by Mr_Person (Hermit) on Jun 13, 2003 at 00:27 UTC | |
|
Re: Parallel::ForkManager question
by perrin (Chancellor) on Jun 13, 2003 at 14:32 UTC | |
|
Re: Parallel::ForkManager question
by BrowserUk (Patriarch) on Jun 13, 2003 at 01:44 UTC |