I have a binary program named as some thing like "mm.out". This program has some unexpected bugs and the bugs causes it to stop. I want to write a service or shell script to execute my binary again if it stopped unexpectedly. How should I write this program?
Asked
Active
Viewed 148 times
-3
-
You should debug your program (use a debugger like `gdb`, and set the core dump file limit to a suitable value). You might write a `while` loop inside a shell script. – Basile Starynkevitch Feb 18 '12 at 18:20
2 Answers
3
You should fix the program. But if you really want this, run it in a loop:
while ! mm.out
do
sleep 5 # Just in case the program dies immediately
done

cnicutar
- 178,505
- 25
- 365
- 392
-
1maybe what he means is to get it to start running once it stops (Automatically) – Feb 18 '12 at 18:21
-
1
-
-
-
If it is, your code is impeccable. Else, we would need to interface it with `ps
| grep mm` or something? – Feb 18 '12 at 18:34 -
@Nunoxic I'm actually a beginner, I'm sure it's flawed. I would go with `pgrep`. – cnicutar Feb 18 '12 at 18:35
1
Let a shell script execute it and wait for a return code, if that code isn't 0 restart the program.

f2lollpll
- 997
- 6
- 15