title: Ignore HUP signal in Bash script with pipe commands
body: <p>I have the following script which monitors the <code>/tmp</code> directory indefinitely and if there are any operations with files in this directory, then file name is read by while loop and first <code>a</code> character in file name is replaced with <code>b</code> character and this modified file name is logged to <code>test.log</code> file:</p>
  
  <pre><code>#!/bin/bash
  
  trap ':' HUP
  trap 'kill $(jobs -p)' EXIT
  
  /usr/local/bin/inotifywait -q -m /tmp --format %f | 
    while IFS= read -r filename; do
      echo "$filename" | sed 's/a/b/' &gt; test.log
    done
  </code></pre>
  
  <p>This is simplified version of the actual script. I also have a Sys-V type init script for the script above and as I would like to stay LSB compliant, my init script has <code>force-reload</code>(<em>Causes the configuration to be reloaded if the service supports this. Otherwise, the service is restarted.</em>) option which sends the HUP signal to script. Now before executing the <code>force-reload</code>, which executes <code>killproc -HUP test.sh</code>, the output of <code>pstree</code> is following:</p>
  
  <pre><code># pstree -Ap 4424
  test.sh(4424)-+-inotifywait(4425)
                `-test.sh(4426)
  # 
  </code></pre>
  
  <p>After executing the <code>strace killproc -HUP test.sh</code> the child shell is terminated:</p>
  
  <pre><code># pstree -Ap 4424
  test.sh(4424)---inotifywait(4425)
  # 
  </code></pre>
  
  <p>According to <code>strace</code>, <code>killproc</code> sent <code>SIGHUP</code> to processes <code>4424</code> and <code>4426</code>, but only the latter was terminated.</p>
  
  <p>What is the point of this child-shell with PID <code>4426</code> in my example, i.e why is it created in the first place? In addition, is there a way to ignore <code>HUP</code> signal?</p>