title: How do I write a watchdog daemon in bash?
body: <p>I want a way to write a daemon in a shell script, which runs another application in a loop, restarting it if it dies.</p>
  
  <ul>
  <li>When run using <code>./myscript.sh</code> from an SSH session, it shall launch a new instance of the daemon, except if the daemon is already running.</li>
  <li>When the SSH session ends, the daemon shall persist.</li>
  <li>There shall be a parameter (<code>./myscript -stop</code>) that kills any existing daemon.</li>
  </ul>
  
  <hr>
  
  <p>(<strong><em>Notes on edit</em></strong> - The original question specified that <code>nohup</code> and similar tools may not be used. This artificial requirement was an "XY question", and the accepted answer in fact uses all the tools the OP claimed were not possible to use.)</p>