Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
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? –  MariusMatutiae Jan 20 '14 at 10:14

1 Answer 1

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 >/dev/null ||; sleep 1; done

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.