On Thu, 2002-04-18 at 18:28, drieux wrote:
>
> On Thursday, April 18, 2002, at 02:27 , Ahmed Moustafa wrote:
>
> > Chas,
> >
> > Thanks a lot!
> >
> >> #the main loop has exited, so we should check to see if there are
> >> #any unreaped children
> >> waitpid $_ for keys %running;
> >
> > My main loop is iterating forever i.e. a daemon; thus, any code after the
> > main loop will not be executed. So, what do you think?
>
> you might want to have your 'main loop' in
>
> our $still_going = 1;
> $SIG{TERM} = sub { $still_going = 0 }; # correcting Chas's Issues... 8-)
> while ( $still_going ) {
> # the main loop
> }
>
> #
> # now to close down gracefully
> #
>
> ciao
> drieux
What issues? I use
my $terminate = 0;
$SIG{TERM} = sub { $terminate = 1 };
until ($terminate) {
#do stuff
}
#cleanup
You should definitely provide some means of cleanly bring down your
daemon. The alternative is someone killing with a signal 9 (SIGKILL)
and who knows what state that will leave the system. The two perennial
favorites are shutting down when you receive a signal (usually signal
15: SIGTERM) and the existence (or lack thereof) a file in /var/run.
Normally I don't invoke and bring down the daemon by hand but rather
provide scripts like these:
<example name="startup">
#!/bin/sh
BASE=/the/base/directory
BIN=$BASE/bin
LOG=$BASE/log
LOGFILE=$LOG/CASPERII.log
$BIN/daemon.pl >> $LOGFILE 2>> $LOGFILE.err
</example>
<example name="shutdown">
#!/bin/sh
PID=`ps -ef | grep daemon.pl | grep "/usr/bin/perl" | awk -e '{print
$2}'`
if [ "$PID" != '' ] ; then
kill -15 $PID
else
echo "Could not find daemon.pl, try 'ps -ef'ing yourself"
fi
</example>
--
Today is Prickle-Prickle the 36th day of Discord in the YOLD 3168
This statement is false.
Missile Address: 33:48:3.521N 84:23:34.786W
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]