title: Sending SIGTERM to all processes
body: <p>I have a bash script call <code>run.sh</code> that launches multiple processes</p>
  
  <pre><code>#!/bin/bash
  proc1 &amp;
  proc2 &amp;
  proc3 &amp;
  final # this runs until sigterm
  </code></pre>
  
  <p>When I execute <code>run.sh</code> and I send a SIGTERM to run.sh, I don't think SIGTERM is being sent to <code>final</code>, and I don't think it is being sent to <code>proc1</code>, <code>proc2</code>, and <code>proc3</code>. Note that in this use case this is a docker container which runs <code>run.sh</code>, and running <code>docker stop</code> is the way I'm trying to send SIGTERM.</p>
  
  <p>What would be the easiest way for the bash script to send a sigterm to all of the processes it started? The only way I can think of is by starting <code>final</code> with the <code>&amp;</code> too and then do a while loop in <code>run.sh</code>?</p>
  
  <p>EDIT - I've tried it though, doesn't seem to work:
  In <code>run.sh</code></p>
  
  <pre><code>#!/bin/bash
  _term() { 
    echo "Caught SIGTERM signal!" 
  }
  trap _term SIGTERM
  echo "hi"
  sleep 100000 &amp;
  wait $!
  </code></pre>
  
  <p>When running docker stop, I never see <code>Caught SIGTERM signal!</code></p>