This is exactly what I would suggest, with the added comment that I have used this approach with excellent results.
use Parallel::ForkManager;
$pm = Parallel::ForkManager->new(2);
foreach my $input_file (@files) {
my $pid = $pm->start and next;
system("shell_script < $input_file");
$pm->finish; # Terminates the child process
}
Your actual code may vary, depending on requirements
This works well on both Windows and UNIX, and as long as the OS manages the SMP tasks correctly, your threads will use both CPUs (one thread will only use one CPU, obviously) if needed.
Updates:
- 2005-10.Oct-26 : updated code to change exec() to system(). Thanks to axl163 for pointing that out!
|