-3

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?

Mat
  • 202,337
  • 40
  • 393
  • 406
Mohammad Sheykholeslam
  • 1,379
  • 5
  • 18
  • 35
  • 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 Answers2

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
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