Complete.Org: Mailing Lists: Archives: linux-help: April 2003:
[linux-help] Re: Keeping a process alive
Home

[linux-help] Re: Keeping a process alive

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: linux-help@xxxxxxxxx
Subject: [linux-help] Re: Keeping a process alive
From: Tom Hull <thull2@xxxxxxx>
Date: Mon, 28 Apr 2003 10:58:59 -0500
Reply-to: linux-help@xxxxxxxxx

John Lucas wrote:
> Hello, all!
> 
> The problem I'm having is that darkice is kind of unstable, meaning it may
> run anywhere from 30 minutes to 30 hours before crashing, but it will
> eventually crash.
> 
> I currently have the darkice configuration set up so that it runs 5 hours 59
> minutes and 45 seconds before shutting down, and I have the crontab set up
> to restart the process every 6 hours.  At best, you get a 15 second gap in
> the audio every six hours; at worst, the server is dead for about 6 hours.
> 
> I'm looking for something to stick in the crontab to check if the darkice
> process is running every 30 minutes or so, and, if it is, leave it alone,
> and if it has died, restart it.
> 
> Perhaps crontab isn't the best answer?  I'm open to suggestions...
> 
> By the way, the darkice encoder insists on running with superuser
> privileges... something about threading.
> 
> Any help is appreciated!

The most effective way to do this would be to write a program which launches
the program you want to keep alive, then waits for it to exit/die, then
relaunches it again. The basic loop is something like:

   forever, do
     fork
     if child process exec program
     if parent process wait on program

Note that this program will be sleeping until the child process exits,
then it can restart it. That gives you no more than a tiny slice of time
w/o the program running. (However, it doesn't verify that the program
is not hung up itself; only that it hasn't exited or been killed.) It
also means that the parent process sleeps until needed, so it doesn't
use any unnecessary cycles. Note that you can also force a restart of
the program by killing it (not the launcher).

You probably want to run this program as a daemon, which is usually
done by having the program initially fork: the parent process then
exits, while the child process calls setpgid() and then goes about
its business.

You can arrange for the daemon process to be launched out of an rc script
(such as rc.local).

The code to do these things is pretty simple. The main things you have
to consider are possible errors and what to do about them.

The above doesn't have to be written in C. You can do similar things
in perl or comparable languages, or even in bash.

> Thanks!
> --John

-- 
/*
  *  Tom Hull * thull2 at cox.net * http://www.tomhull.com/
  */

-- This is the linux-help@xxxxxxxxx list.  To unsubscribe,
visit http://www.complete.org/cgi-bin/listargate-aclug.cgi


[Prev in Thread] Current Thread [Next in Thread]