使用Parallel :: ForkManager启动多个应用程序

时间:2013-08-31 05:16:24

标签: perl parallel-processing

我使用perl的Parallel::ForkManager并行启动多个应用程序。我有两个子程序,一个用于启动应用程序,另一个用于对由于应用程序完整运行而生成的输出文件执行数据处理。 在第一个子例程中,我system()调用cd到所需目录并在那里启动应用程序。我在system()调用后调用第一个子例程中的第二个子例程。

问题是,在启动所有运行之后,程序退出并且第二个子例程完成的数据处理永远不会完成,我所拥有的只是运行完成后出现的应用程序的输出文件背景。

这是我正在做的事情的代码

#!/usr/bin/perl -w
use strict;
use Parallel::ForkManager;
use Getopt::Long;

# Get input from the command line. Also get max_no_processes for Parallel::ForkManager
# Perform operations on the input file and seperate out data from them in form of arrays.   
# The arrays thus formed contain arguments for the application and path_to_directory where operation is to be performed

my $pm = new Parallel::ForkManager($max_no_processes);

for (my $i = 0; $i < $#input; $i++){  #----> @input is the array containing the input for  the application. using its length as max value.
    $pm->start and next;
    &subroutine1( $input[$i], $path_to_directory[$i] );
    $pm->finish;
}

$pm->wait_all_children;

sub subroutine1{
    my($input, $dir) = @_;

    system("cd dir && APPLICAION -$input");

    &subroutine2($dir);
}

sub subroutin2{
     my ($dir) = @_;

     # data processing
     # print to stdout and file
}

0 个答案:

没有答案
相关问题