title: How to check whether a background job is alive? (bash)
body: <p>I have the following bash script, we can call it <code>script1.sh</code>:</p>
  
  <pre><code>#!/bin/bash
  
  exec ./script2.sh &amp;
  
  sleep 5
  
  if job1 is alive then #&lt;--- this line is pseudo-code!
      exec ./script3.sh &amp;
      wait
  fi
  </code></pre>
  
  <p>As can be seen, the script executes <code>script2.sh</code> as a background job and then waits 5 seconds (so <code>script2.sh</code> can do some initialization stuff). If the initialization succeeds, the <code>script2.sh</code> job will still be alive, in which case I also want to start <code>script3.sh</code> concurrently; if not, I just want to quit.</p>
  
  <p>However, I do not know how to check whether the first job is alive, hence the line of pseudo-code. So, what should go in its place?</p>