title: (Linux) how to make wait watch sub-process of a sub-process
body: <p>The code I am trying to use (shell script in korn) is this:</p>
  
  <pre><code>load_x ()
  {
  consumer_load &amp;
  producer_spool
  }
  
  while read line
  do
    load_x &amp;
  done &lt; list_of_loads
  wait
  </code></pre>
  
  <p>In a nutshell I am trying to read a list of tables from a flat file, then triggering their loads in parallel. I am also triggering the consumer_load function in background so that the producer_spool function can feed data to it through a named pipe.
  The issue I am facing is that the wait statement does not seem to work for the inner sub-process fired in background (consumer_load &amp;). i.e. it does wait for the load_x function to finish, but does not wait for consumer_load to finish and moves to the next statement.
  In this case, if the producer_spool function finishes before consumer_load, the script will end even if the consumer_load is still running.
  Is there a way to get a script to wait for all sub-processes? Would putting wait inside load_x (as the last line) work?</p>