title: Terminate running commands when shell script is killed
body: <p>For testing purposes I have this shell script</p>
  
  <pre><code>#!/bin/bash
  echo $$
  find / &gt;/dev/null 2&gt;&amp;1
  </code></pre>
  
  <p>Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.</p>
  
  <pre><code>$ ./test-k.sh
  13227
  &lt;Ctrl+C&gt;
  $ ps -ef |grep find
  $
  </code></pre>
  
  <p>Running it in the background, and killing the shell only will orphan the commands running in the script. </p>
  
  <pre><code>$ ./test-k.sh &amp;
  [1] 13231
  13231
  $ kill 13231
  $ ps -ef |grep find
  nos 13232     1  3 17:09 pts/5    00:00:00 find /
  $
  </code></pre>
  
  <p>I want this shell script to terminate all its child processes when it exits regardless of how it's called. It'll eventually be started from a python and java application - and some form of cleanup is needed when the script exits - any options I should look into or any way to rewrite the script to clean itself up on exit?</p>