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?
Don’t reinvent the wheel, use the daemon command with
--respawn.You should also consider the options
--acceptable,--attemptsand--delayto make sure buggy processes don’t cause endless respawn-loops (for example when they die immediately because of a wrong command line option).