0

I have a program that should run all the time (it collects some statistics) after Xorg start. However, there can occur some exceptions in this program, or it can be unintentionally closed, and what I want is to automatically restart it. The first idea is to run every minute another script with cron, which will restart it, but this doesn't seem optimal, so what's the preferred method of doing this?

1
  • Can you give us some extra info? For instance: is the program supposed to perform a service, so that it cannot even tolerate a 5 minute gap? Is is performing some computation, so that it can tolerate a 5-minute gap, but must be fed some complex input upon start? Jan 20, 2014 at 10:14

1 Answer 1

0

There are many ways of doing this and which one you choose depends on how the script is being run. An easy way that works for any command and does not require root access is to run something like this:

while true; do pgrep -f myscript.sh >/dev/null || myscript.sh; sleep 1; done

This will run for ever (while true) and launch myscript.sh if it is not already running.

You must log in to answer this question.