1

If my software has aborted because of an error, is there a way so that my Ubuntu will right away re-open it? I'm using g++ sample.cpp -o sample and ./sample

But if it crashes it's really a problem for me. What would be the solution? Thanks.

4 Answers 4

4

A simple bash script?

#! /bin/bash until ./my_app; do sleep 2 # To prevent insanity done 
Sign up to request clarification or add additional context in comments.

2 Comments

Better than the accepted answer because it gives the program the ability to willingly exit.
I'm using ubuntu and doing this root@monstenation:~# !/bin/bash -bash: !/bin/bash: event not found Why is that?
1

Simple solution would just be to make a shell script to start the program every time it finishes execution.

example:

#!/bin/bash while true do ./sample done 

You may want to save a log file or the program output each time sample finishes execution.

3 Comments

One possible problem with this (and some of the other solutions) is that if something goes wrong that causes the program to crash quickly every time you start it, you'll be running it many many times. You might consider adding a sleep to the loop.
I'm using ubuntu and doing this root@monstenation:~# !/bin/bash -bash: !/bin/bash: event not found Why is that?
Save the contents into a script, ex foo.sh. Then make it executable with chmod +x foo.sh. Then execute like so: ./foo.sh. Alternatively you can enter each line at the bash prompt, just leave off the first line (although you should probably save it as a script if you plan on running it again).
0

Another approach is to have a master daemon which gets frequent heart beats from the program which you want to monitor and when heart-beats are not received, start the program which is being watched.

Comments

0

Possibly overkill for what you're after, it's hard to tell, but the God monitoring framework might help - a little more advanced and feature-ful than a simple while(1)

2 Comments

Good god (no pun intended, but...), that is one heck of a system - it stops short of rewriting an entire shell (and may do things a shell cannot).
Well yes, I did say it might be a little overkill ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.