1

A Bash script I have been working on calls some processes in background. I have used "wait" in the parent Bash script to wait for all the background processes to finish. Runs fine.

However, the problem is with restart. I want that if any of the child process ends it should get started again. I tried a forever loop using using While and checking the process status using pgrep and issue restart. But that will consume resources.

Is there any other possibility to restart the child background process as soon as it stops/killed/terminates?

Ankit
  • 197
  • 1
  • 8

1 Answers1

1

Don't reinvent the wheel, use the daemon command with --respawn.

You should also consider the options --acceptable, --attempts and --delay to make sure buggy processes don't cause endless respawn-loops (for example when they die immediately because of a wrong command line option).

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • The daemon command option looks good. Trying my hands, still unclear of how to use it: daemon --name processname -X executable -c /configurationfileneededbyexecutable/ Does Not work. – Ankit Feb 06 '13 at 10:34
  • Figured it out. Thanks Aaron. Works!! – Ankit Feb 06 '13 at 11:19
  • `-c` is for `daemon`, not for the process you want to start. If you need to pass arguments to the executable, you have to wrap it in a script. – Aaron Digulla Feb 06 '13 at 11:38