title: How to make a process monitor your program to restart it if it exits
body: <p>So i have my program, but i don't want it to be able to be closed. I know its not possible to make it 100% unclosable but this method seems like it would work the best.</p>
  
  <p>I realize that you can <code>addShutdownHook</code>, but this will not work if the process is killed in from the operating system, using Task Manager (Windows) or <a href="https://stackoverflow.com/questions/2541597/how-to-gracefully-handle-the-sigkill-signal-in-java"><code>kill -9</code></a> (Unix). Obviously, if I have a second process running and the main one is killed it can just re-run the main one again, which makes it much more reliable.</p>
  
  <p>So, I want to know how to create a <a href="https://stackoverflow.com/a/25761097/545127"><em>watchdog</em> process</a> in Java that monitors my actual Java application to detect if it has been closed, then if it has been closed it re-executes the program.</p>