开发者

Auto re-run, Linux

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

B开发者_运维知识库ut if it crashes it's really a problem for me. What would be the solution? Thanks.


A simple bash script?

#! /bin/bash

until ./my_app; do
    sleep 2 # To prevent insanity
done


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.


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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜