title: Bash: wait with timeout
body: <p>In a Bash script, I would like to do something like:</p>
  
  <pre><code>app1 &amp;
  pidApp1=$!
  app2 &amp;
  pidApp2=$1
  
  timeout 60 wait $pidApp1 $pidApp2
  kill -9 $pidApp1 $pidApp2
  </code></pre>
  
  <p>I.e., launch two applications in the background, and give them 60 seconds to complete their work. Then, if they don't finish within that interval, kill them.</p>
  
  <p>Unfortunately, the above does not work, since <code>timeout</code> is an executable, while <code>wait</code> is a shell command. I tried changing it to:</p>
  
  <pre><code>timeout 60 bash -c wait $pidApp1 $pidApp2
  </code></pre>
  
  <p>But this still does not work, since <code>wait</code> can only be called on a PID launched within the same shell.</p>
  
  <p>Any ideas?</p>