#!/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; }