title: Run multiple jobs within perl script at the same time
body: <p>I have to run video encoding program, where I have different quantization parameters QP. QP goes from 0 to 51. In my perl script I iterate over this parameter and execute command line. The command line is qiven with:</p>
  
  <blockquote>
    <p>TAppEncoder encoder_intra_main_rext.cfg -i BSEQ.RAW -b BSEQ_1.bin -o /dev/null -qp 1 -wdt 7811 -hgt 7911 -fr 1 -fs 0 -f 2 --InputBitDepth=16 --OutputBitDepth=16 --InternalBitDepth=16 --InputChromaFormat=400 --ConformanceMode=1 --SEIDecodedPictureHash >> BSEQ_1.txt</p>
  </blockquote>
  
  <p>In each iteration I change ONLY qp. Now, in my Perl script when I execute the line above, it waits to finish and than proceed to the next iteration in the loop (e.g. <code>qp=2</code>).</p>
  
  <p>Also perl script has been called by the top level shell script:</p>
  
  <pre><code>test.sh ---&gt; test.pl ---&gt; command1 with qp=1
                       ---&gt; command2 with qp=2
                       ---&gt; command3 with qp=3
                       ---&gt; command4 with qp=4
                       ---&gt; until the end of the for loop
  </code></pre>
  
  <p>I was wondering how to run two (or more) processes in parallel. For example, to run <code>qp=1</code> and immediately after <code>qp=2</code>, without waiting <code>qp=1</code> to finish. And than when one of those two is done (no matter if qp=1 or qp=2 finished first) to run qp=3, and so on.</p>
  
  <p>So basically, I do not want to run the perl script in parallel, do not need multiple instances of the perl script. I need command within script (which is part of the loop) to be run in parallel. However, if there is other way to accomplis this, let me know.</p>
  
  <p>The part of the code is below, now it runs one qp at the time. I want to run 2 in the parallel all the time, once one is done to go to the next, so all the time 2 processes are running.</p>
  
  <p>I'm running scripts on linux mint. Im running it on one computer (I do not have a cluster). The idea is to tun it on a two cores.</p>
  
  <p>Any idea how to accomplish that, or at least where to start?
  Thanks.</p>
  
  <pre><code>    $QP_end = $Configuration-&gt;{nb_QPs}-1;
      foreach $QP_index (0 .. $QP_end)
      {
        $QP = $Configuration-&gt;{QP_list}[$QP_index];
        print($QP," ");
        set_command_line(); # HERE I CHANGE THE QP TO SET NEW COMMAND LINE, AND THEN EXECUTE THE NEW COMMAND
        @RunCommand = ($command_line);
        `@RunCommand`;
      }
  </code></pre>