I'm building a simple daemon in perl ("ko") that fires off processes as soon
as the loading on our batch server is low enough to handle them. Someday I
hope to put in some custom logic that runs more at night, fewer in the day,
etc.
Problem: I can launch the daemon on the irix server, but I can't logout
unless I kill the daemon.
ralph% rlogin spock
spock% ko
Starting batch job (pid: 2885166), 24 input files found.
Progress recorded in file ko.out.
spock% logout
... Here it hangs until I open a new window, rlogin spock, do a "killall
ko", then it drops me back to a prompt on ralph.
Any ideas? Below is the daemon code, adapted from the Perl Cookbook.
Thanks!!
- Bryan
**************************************
use POSIX 'setsid';
$SIG{CHLD} = 'IGNORE'; # don't wait for children to exit
# turn myself into a daemon (background myself)
$pid = fork and exit(0);
defined($pid) or die "$me: Couldn't background: $!, exiting.\n";
POSIX::setsid() or die "$me: Couldn't start a new session: $!, exiting.\n";
for my $handle (*STDIN, *STDERR) {
open($handle, "+<", "/dev/null") or die "$me: Can't reopen $handle to
/dev/null: $!. Exiting.\n";
}
# open ko.out file for further recording
$outfile = "ko.out";
open(KOFILE,">$outfile") or die "ko: Couldn't open $outfile: $!\n";
print "Starting batch job (pid: $$), $tn input files found.\n";
print "Progress recorded in file $outfile.\n";
select KOFILE; # push all STDOUT to KOFILE
$| = 1; # and don't buffer it
print "Starting batch job (pid: $$), $tn input files found.\n";
**************************************