title: How to run a background shell script which itself lauches two background processes?
body: <p>To start with, I am a beginner to programming etc so apologies for lack of professionally accurate terminology in my question but hopefully I will manage to get my points across!</p>
  
  <p>Would you have any suggestions how in bash or tcsh I can run a long background process which itself launches a few programs and has to run three long processes in parallel on different cores and wait for all three to be completed before proceeding...?</p>
  
  <p>I have written a shell script (for bash) to apply an image filter to each frame of a short but heavy video clip (it's a scientific tomogram actually but this does not really matter). It is supposed to:</p>
  
  <ol>
  <li><p>Create a file with a script to convert the whole file to a different format using an em2em piece of software.</p></li>
  <li><p>Split the converted file into three equal parts and filter each set of frames in a separate process on separate cores on my linux server (to speed things up) using a program spider. Firstly, three batch-mode files (filter_1/2/3.spi) with required filtration parameters are created and then three subprocesses are launched:</p>
  
  <pre><code>spider spi/spd @filter_1 &amp;  # The first process to be launched by the main script and run in the background on one core
  spider spi/spd @filter_2 &amp;  # The second background process run on the next core
  spider spi/spd @filter_3    # The third process to be run in parallel with the two above and be finished before proceeding further.
  </code></pre>
  
  <p>These filtered fragments are then put together at the end.</p></li>
  </ol>
  
  <p>Because I wanted the 3 filtration steps to run simultaneously, I sent the first two to background with a simple &amp; and kept the last one in the foreground, so that the main script process will wait for all three to finish (should happen at the same time) before proceeding further to reassemble the 3 chunks. This all works fine when I run my script in the foreground but it throws a lot of output info from the many subprocesses onto the terminal. I can reduce it with:</p>
  
  <pre><code>$ ./My_script 2&gt;&amp;1 &gt; /dev/null
  </code></pre>
  
  <p>But each spider process still returns </p>
  
  <pre><code>*****Spider normal stop*****
  </code></pre>
  
  <p>to the terminal. When I try to send the main process to background it keeps stopping all the time.</p>
  
  <p>Would you have any suggestions how I can run the main script in the background and still get it to run the 3 spider sub-processes in parallel somehow?</p>
  
  <p>Thanks!</p>