in reply to Best way to make a script run persistently (daemon)

Glad you asked this question, as it's something I'm going to have to grapple with in a few days. I'll watch this thread with interest to see if the answer to my question comes up :)

At the moment, how I'm planning to approach it (subject to revision by sibling monks) is
while (1) { open OFF, "off.txt"; last if <OFF>; # all the code goes here sleep 5; } print "you turned me off!";
off.txt is a blank file. So then my script runs and runs and runs until I put something into off.txt, at which point the script breaks out of the loop.

As I say, that's how I'd do it... but I'd also ask how to do it before I did it that way. As you have.

§ George Sherston

Replies are listed 'Best First'.
Re: Re: Persistence
by Ven'Tatsu (Deacon) on Oct 09, 2001 at 00:18 UTC
    I prefer the file test operators to opening the file and reading from it to stop a daemon. It is probably faster and it is easyer to understand.
    until (-e "off.txt") { #change -e to -s to behave like George's code #code here sleep 5; }