title: How do making processes with & (in bash) and killing them work?
body: <p>I have a script that launches another script in the background, and then terminates it. I was expecting the child script to be gone, but in the end it still manages to print some output. Here is the example:</p>
  
  <p>in script one.sh:</p>
  
  <pre><code>echo "this is one"
  ./two.sh &amp;
  sleep 1
  pid=$!
  kill $pid
  echo "this was one"
  </code></pre>
  
  <p>in script two.sh:</p>
  
  <pre><code>echo "this is two"
  ./three.sh
  echo "this was two"
  </code></pre>
  
  <p>in script three.sh:</p>
  
  <pre><code>echo "this is three"
  sleep 5
  echo "this was three"
  </code></pre>
  
  <p>I ran ./one.sh which is supposed to run two.sh in the background, which in turn runs three.sh but not in the background! The output is get is:</p>
  
  <pre><code>this is one
  this is two
  this is three
  this was one
  this was three
  </code></pre>
  
  <p>Shouldn't "this was three" not appear in the output since three.sh was not ran in the background and two.sh was terminated by one.sh? Could you also point me towards any documentation that describes how processes behave when (not) in background and what happens when they are terminated?</p>
  
  <p>Thank you very much for all your help!</p>