Ok, so I think I kinda got the hang of fork() (be gentle, today was my first time ever trying it (: ) but what's say I have a program that I want the maintainer to have the choice to daemonize or not. What's say, more, that if the script daemonizes all output should go to a file log vs STDOUT. Otherwise, all output goes to STDOUT (or STDERR of course which means that STDERR needs to go to a logfile too if we daemonize). How would I do this?
My current forking code...
## Should this program daemonize...
## ie: should it run all the time
## in the background?
my $daemonize = 1;
##################################################
# fork code
if ( $daemonize ) {
my $pid = fork();
die("fork() failed: $!") unless defined $pid;
## need to do something right here
## to get STDOUT and STDERR to go
## to a file vs the console/screen.
if ($pid) {
exit(0);
}
}
----------
- Jim