title: launching multiple applications using Parallel::ForkManager
body: <p>I am using perl's <code>Parallel::ForkManager</code> to launch multiple applications in parallel. I have two subroutines, one for launching the application and other for performing data processing on the output files generated as a result of the application's complete run. 
  In the first subroutine, I make a <code>system()</code> call to <code>cd</code> to the desired directory and launch the application there. I call the second subroutine inside the first subroutine after the <code>system()</code> call. </p>
  
  <p>The problem is that after all the runs are launched, the program exits and the data processing that is done by the 2nd subroutine never gets completed, all I have are the output files of the application that appear after the runs are completed in the background.</p>
  
  <p>Here is my code of what I am doing</p>
  
  <pre><code>#!/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 &lt; $#input; $i++){  #----&gt; @input is the array containing the input for  the application. using its length as max value.
      $pm-&gt;start and next;
      &amp;subroutine1( $input[$i], $path_to_directory[$i] );
      $pm-&gt;finish;
  }
  
  $pm-&gt;wait_all_children;
  
  sub subroutine1{
      my($input, $dir) = @_;
  
      system("cd dir &amp;&amp; APPLICAION -$input");
  
      &amp;subroutine2($dir);
  }
  
  sub subroutin2{
       my ($dir) = @_;
  
       # data processing
       # print to stdout and file
  }
  </code></pre>