title: bash script launching many processes and blocking computer
body: <p>I have written a bash script with the aim to run a .py template Python script 15,000 times, each time using a slightly modified version of this .py.
  After each run of one .py, the bash script logs what happened into a file.</p>
  <p>The bash script, which works on my laptop and computes the 15,000 things.</p>
  <pre><code>N_SIM=15000
  for ((j = 1; j &lt;= $N_SIM; j++))
  do
      index=$((j))
      a0=$(awk &quot;NR==${index} { print \$1 }&quot; values_a0_in_Xenon_10_20_10_25_Wcm2_RRon.txt)
      dirname=&quot;a0_${a0}&quot;
      mkdir -p $dirname
      cd $dirname
      awk -v s=&quot;a0=${a0}&quot; 'NR==6 {print s} 1 {print}' ../integration.py &gt; integrationa0included.py
      mpirun -n 1 python3 integrationa0included.py 2&amp;&gt; integration_Xenon.log &amp;
      cd ..
  done
  </code></pre>
  <p>It launches processes and the terminal looks like (or something along these lines, the numbers are only there for illustrative purposes, they are not exact):</p>
  <pre><code>[1]
  [2]
  [3]
  ...
  ...
  [45]
  [1]: exit, success (a message along these lines)
  [4]: exit, success
  [46]
  [47]
  [48]
  [2]: exit, success
  ...
  </code></pre>
  <p>And the pattern of finishing some launched processes and continuously launching new ones repeats up until the 15,000 processes are launched and completed.</p>
  <p>I want to run this on a very old computer.
  The problem is that it launches almost instantly 300 such processes and then the computer freezes. It basically crashes. I cannot do CTRL+Z or CTRL+C or type. It's frozen.</p>
  <p>I want to ask you if there's a modification to the bash script which launches only 2 processes, waits for 1 to finish, launches the 3rd, waits for the 2nd to finish, launches the 4th, and so on.
  So that there aren't so many processes waiting at any given time. Maybe this doesn't block the old computer.</p>