in reply to Process Reliablity

How about catching the SIGCHLD messages and using that as your trigger to start the process again. Something along these lines.
#!/usr/bin/perl -w use strict; launch_child(); $SIG{CHLD}=\&launch_child; sleep 60 while(1); sub launch_child{ print "$$ parent spawning a child\n"; my $pid=fork; if(!$pid){ print "$$ inside the child\n"; # all the code that does the real work is in here # all the other stuff is just a wrapper to keep # this bit going sleep 60 while(1); } }
If you really care about your process you'll back this up with some of the methods mentioned above. You may also want to put some checks on to keep the process from thrashing (constantly restarting the process, which immediately dies again, etc...) just in case. This technique does have the nice side-effect that the restarts are nearly instentaneous.

Replies are listed 'Best First'.
RE: Re: Process Reliablity
by DrManhattan (Chaplain) on Jul 20, 2000 at 18:40 UTC

    That's an interesting solution, but it's likely to dump core. From perlipc:

    Do as little as you possibly can in your [signal] handler ... because on most systems, libraries are not re-entrant; particularly, memory allocation and I/O routines are not. That means that doing nearly anything in your handler could in theory trigger a memory fault and subsequent core dump.

    -Matt

      Under normal situations that would be the case, but since my main program doesn't do anything other than sleep there are no non-reentrant pieces of code that could be interrupted by the dying process (causing a core dump). I have used this technique before and it has proven to be quite stable.