Question:
is there a way autostart program if it crashes?
Levi
2010-09-02 17:32:16 UTC
I know people can use scripts and what not for UNIX, but im wondering if it is possible restart an unmanned server program if it crashes it the middle of the day so it just restarts itself
Three answers:
Ratchetr
2010-09-02 17:44:11 UTC
Yes, there are always ways to do that.

But to give you a good answer, we really need more details:

What OS?

What normally starts the program? e.g. is it a Linux Deamon? A Windows service? A program you have in your (Windows) startup folder?

Do you have, and can you change, the source code for the program itself?
ʄaçade
2010-09-02 17:57:04 UTC
Read man 8 init. As above, it helps if you specify which OS you are using. Here I am assuming you are running some flavour of Linux.



Note the files in /etc/init. Here is one of them. ...



| # tty - getty

| #

| # This service maintains a getty on the specified device.

|

| stop on runlevel [016]

|

| respawn

| instance $TTY

| exec /sbin/mingetty $TTY





Note the 'respawn' declaration. That causes init to restart the dæmon whenever it stops.



Yes, you can always make a wrapped around it as ...



while [ 1 ]; do run_your_programme; done



... which will work in most operating systems, including Cygwin.
Jim
2010-09-02 17:47:26 UTC
you have to write a polling program which checks periodically every 15 seconds the list of windows or the list of processes for the process you want, and if it isn't there, Run it.

you don't want to poll a lot, and you want to make sure this thing wakes up on a timer activity, otherwise you are consuming 100% cpu.



you could do this with auto-it3 or any other language I suppose, I would do it in C++ with windows callbacks.



you should debug and fix your program.



to stop the target program from running, you would have to stop the controller from running.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...