title: bash restart sub-process using trap SIGCHLD?
body: <p>I've seen monitoring programs either in scripts that check process status using 'ps' or 'service status(on Linux)' periodically, or in C/C++ that forks and wait on the process... </p>
  
  <p>I wonder if it is possible to use bash with trap and restart the sub-process when SIGCLD received?</p>
  
  <p>I have tested a basic suite on RedHat Linux with following idea (and certainly it didn't work...)</p>
  
  <pre><code>#!/bin/bash
  set -o monitor # can someone explain this? discussion on Internet say this is needed
  trap startProcess SIGCHLD
  startProcess() { 
    /path/to/another/bash/script.sh &amp; # the one to restart
    while [ 1 ]
    do
      sleep 60
    done
  }
  startProcess
  </code></pre>
  
  <p>what the bash script being started just sleep for a few seconds and exit for now.</p>
  
  <p>several issues observed: </p>
  
  <ul>
  <li>when the shell starts in foreground, SIGCHLD will be handled only once. does trap reset signal handling like signal()? </li>
  <li>the script and its child seem to be immune to SIGINT, which means they cannot be stopped by ^C </li>
  <li>since cannot be closed, I closed the terminal. The script seems to be HUP and many zombie children left.</li>
  <li>when run in background, the script caused terminal to die</li>
  </ul>
  
  <p>... anyway, this does not work at all. I have to say I know too little about this topic. 
  Can someone suggest or give some working examples? 
  Are there scripts for such use?</p>
  
  <p>how about use wait in bash, then?</p>
  
  <p>Thanks</p>