Feb 19, 2001, 5:26 PM
Post #1 of 1
Please Help With Daemon
I need some help in running a constant process, I'm afraid to use gotos because I don't want to open a data base a billion times a minute or anything, all I'm aiming for is to get my script to re run every 20 seconds. I've tried everything from a simple daemon, to goto's. The deamon I've been playing with after doing some research is as follows,
I need the script to load through the browser too, so this doesn't work because since it's sleeping so often it doesn't give the browser a chance to even load the script and start looping through the print. And goto's seem too dangerous, Also I have the same problem with sleep(); using goto's.
use POSIX qw(setsid);
chdir '/' or die "Can't chdir to /: $!";
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
#open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
open STDERR, '>/dev/null' or die "Can't write to /dev/null: $!";
defined(my $pid = fork) or die "Can't fork: $!";
exit if $pid;
setsid or die "Can't start a new session: $!";
Does anyone have any ideas? I'm actually re-writing this code, What it did before was pop up a window if something happend in a database, it would refresh the script every 20 seconds, but due to the independability of servers, often the iframe which i was refreshing in would go dead and not run the script anymore. Of course only I would know to refresh it.
Any ideas are greatly appreciated.