![]() |
|
#1
|
|||
|
|||
Program Automatic Restart after failure.Hi all...
I have a socket program, which runs fine. It just receives values from another socket. What i want with this code is that if it crashes, it should automatically restart itself. Can anyone throw some ideas on this? The code is below: CPP / C++ / C Code:
Last edited by LuciWiz : 02-May-2008 at 14:23.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#2
|
|||
|
|||
Re: Program Automatic Restart after failure.Hi,
A program may crash for different reasons, and you can control some of them. You also have to define which errors are recoverable. I think we have two main reasons:
Regards __________________
Please, correct me if I'm wrong, and sorry for my english ;) |
|
#3
|
|||
|
|||
Re: Program Automatic Restart after failure.HI,
Thanks for your reply. Lemme try it...if there's a problem, I'll get back...!! |
|
#4
|
|||
|
|||
Re: Program Automatic Restart after failure.Ok...signal is one...
now i have another idea... If my program crashes, my program should automatically send a mail to 'root' stating that the program has crashed. Is this possible? I can write a shell script for that and invoke that script through system() command in the above C program. |
|
#5
|
|||
|
|||
Re: Program Automatic Restart after failure.Quote:
Or, putting it another way, if you put something in the program that checks to make sure the message is properly formed (instead of just assuming that it's OK as your program seems to do), it wouldn't crash at that point, would it? See Footnote. Assuming that there is a bug (or two) that can cause a crash, you could write a shell script that checks to see whether there is a process with a particular name, and it could do whatever you need in case no such process is running. Suppose the process is named 'ThisIsASpecialSomething'. Then you could make a bash script to check periodically: Code:
You would probably launch this "alarm" script in the background and keep it active for as long as you expected the other program to be running. Regards, Dave Footnote: I have been trying for many years to get computer architects to implement a "Branch On Bug" machine instruction, but I haven't been successful. Maybe some day... |
|
#6
|
|||
|
|||
Re: Program Automatic Restart after failure.The shell script thing is a good idea, I must admit.
What I really meant from the above post is this: Consider an example from my source code itself: static void error_report ( const char *on_what ) { perror ( on_what ); system ("mail root :error has occurred" );//I want to use Linux's mail program to mail root that a program has crashed. So, that the root can again restart it. exit ( EXIT_FAILURE ); } Is this possible within a C code? else as you pointed out write a shell script that invokes after a certain intervals of time and checks whether the program is executing or not. |
|
#7
|
|||
|
|||
Re: Program Automatic Restart after failure.Quote:
Quote:
Since your code has this in it, I have to ask whether it works. If it works, then why would you ask whether it is possible? If it doesn't work then I have to ask what happens when you try it? Try things like man sendmail, man mail, and, maybe man syslog. Regards, Dave |
|
#8
|
|||
|
|||
Re: Program Automatic Restart after failure.OK..lemme try it..I get back ASAP
|
|
#9
|
|||
|
|||
Re: Program Automatic Restart after failure.Quote:
1. Try from a command line. Make sure it does exactly what you want. 2. Put the command line into the system call. Regards, Dave |
|
#10
|
|||
|
|||
Re: Program Automatic Restart after failure.Ya,
thanks this is what I am trying now! |
Recent GIDBlog
More photos on Flickr by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Two-Tier data dissemination code installation problem | nidhibansal1984 | Computer Software Forum - Linux | 6 | 16-Sep-2007 10:13 |
| BOOKEEPING program, HELP!! | yabud | C Programming Language | 10 | 17-Nov-2006 03:48 |
| Help with a complex program | lordfuoco | C++ Forum | 5 | 24-Jun-2006 06:03 |
| How to read particular memory location ? | realnapster | C Programming Language | 10 | 10-May-2006 09:11 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The