title: Signalling a bash script running in the background in an infinite loop
body: <p>I have a bash script (sleeping in an infinite loop) running as a background process. I want to periodically signal this process, to do some processing without killing the script, ie. the script on receiving the signal should run a function and then go back to sleep. How do I signal the background process without killing it?</p>
  
  <p>Here's what the code looks like for the script test.sh:</p>
  
  <pre><code>MY_PID=$$
  echo $MY_PID &gt; test.pid
  
  while true
  do
    sleep 5
  done
  trap 'run' SIGUSR1 
  
  run()
  {
   // data processing
  }
  </code></pre>
  
  <p>This is how I am running it and triggering it:</p>
  
  <pre><code>run.sh &amp;
  
  kill -SIGUSR1 `cat test.pid`
  </code></pre>