title: killing a process kills other processes
body: <p>I have a shell script I wrote which does the following steps within a finite loop:</p>
  
  <p>I spawn a process, and wait for it to finish. If it does not finish within 40 seconds, I execute:</p>
  
  <pre><code>kill -SIGTERM pid
  </code></pre>
  
  <p>I have found sometimes, even by doing the kill -SIGTERM pid, the process doesn't respond to being killed. In this case, after an additional 40 seconds of waiting for it to kill itself, I then execute:</p>
  
  <pre><code>kill -9 pid
  </code></pre>
  
  <p>Most times this is sufficient, and I move on to the next iteration of these steps. </p>
  
  <p>THE PROBLEM:
     Sometimes in doing the above set of steps, I end up having not only the process I intended to kill, killed, but also the shell running the script which executes the loop of these steps.</p>
  
  <p>QUESTION: What causes this?</p>