in reply to Processing a set of resources with a pool of forked children
Here is the bare bones way to do it. You didn't say exactly what your problem was in the code.
#!/usr/bin/perl use warnings; use strict; my %pids; my @to_be_processed = (1..20); my $cmd = 'echo'; foreach my $p (@to_be_processed){ $pids{$p}{'pid'} = open($pids{$p}{'fh'}, "$cmd $p 2>&1 |"); } foreach my $key(keys %pids){ my $fh = $pids{$key}{'fh'}; while (<$fh>){ print $_; #stuff data here into a return hash } } foreach my $key(keys %pids){ waitpid($pids{$key}, 1); } print "done\n";
|
|---|