title: How do you kill all child processes without killing the parent
body: <p>I have a script which runs a background process at the beginning, then towards the end needs to stop that background process and its children, THEN do some other tasks etc then return an error code if necessary. How do I do this? I have seen several examples of how to kill the whole tree including the parent process (eg <code>kill 0</code>) but I want the main script to continue running and return the right error code. E.g.:</p>
  
  <pre><code>./some_process_with_child_processes &amp;
  ./do_stuff
  kill $! # doesnt kill child processes!
  ./do_other_stuff
  exit 5
  </code></pre>