title: bash - getting exit codes from 2 called programs that work asynchronously together
body: <p>I know how to get exit code from last called program. But how can I check exit codes in the following scenario</p>
  
  <pre><code>prog1 &amp;
  prog2 &amp;
  
  while [ true ]; do # main loop
      while [ condition1 ]; do
          prog1 &lt;input &gt;output
      done
  
      while [ condition2 ]; do
          prog2 &lt;input &gt;output
      done
  done
  </code></pre>
  
  <p>my goal is to break the main loop and clean up processes after program 1 or 2 exits (with code  =0 or !=0). </p>
  
  <p>For instance: </p>
  
  <ol>
  <li><p>Program 1 exits with code 0. Then I want to kill program2 and exit my script. </p></li>
  <li><p>Program 2 exits with code 333. Then I want to kill program1 and exit script with code 222.</p></li>
  </ol>