The following snippet handles two signals:
INT - close open filehandles and exit
HUP - print a message to a log file
My problem is that I can't seem to access STDOUT, or any file handle that I tie to my log file. It seems that the only descriptor I can get any results from is STDERR.
Here's the code:
My problem is (specifically) - the "HUP caught" never gets logged to the STDOUT log file.use strict; use POSIX; my $die = 0; my $pid = fork; die "no fork\n" unless defined($pid); exit if $pid; close STDIN; open(STDOUT, '>>access.log'); open(STDERR, '>>error.log'); POSIX::setsid(); umask(0); print STDERR "daemon started as pid $$\n"; $SIG{INT} = sub { $die = 1; close STDERR; close STDOUT; }; $SIG{HUP} = sub { print STDOUT "HUP caught\n" }; until ($die) { sleep(2); }
If I replace all instances of STDOUT with STDERR - I will see the "HUP caught" message in its respective log file. STDERR works just fine.
If I replace all instances of STDOUT with some other descriptor (LOG) - I still do not see the HUP message.
Adding 'select(STDOUT)' does no good.
So, is STDERR the only available descriptor to a daemon
process (surely not) - or am I missing something?
and if I am missing something, what is it?
Thanks,
Jeff
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)
In reply to STDOUT and daemon processes by jeffa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |