cidaris has asked for the wisdom of the Perl Monks concerning the following question:
I am using the following method to fork off and dissociate from the terminal for a script I want to daemonize.
Now, I'm told I could just do some while(1) { sleep; } trickery, but I would think there'd be a way to do it without resorting to that. The script should last forever as is, as it uses File::Tail to watch a log.
Permissions are OK, as if I remove the sighandler stuff, I can watch it output exactly what I'm looking for.
Now, I would think that it would run forever (as long as the file was moving) and occasionally print the signals it received, except it dies immediately because the fork kills it. Does someone have a tutorial or a link they could present to do what I think I'm trying to do? Alternatively, education as to WIDIAW (why i'm doing it all wrong) would also be appreciated :) Does the file being rotated out kill File::Tail? The documentation suggests that it handles that situation. Update: It's fairly obvious why it's quitting to me (quit) Forget that part, the question still stands, am I daemonizing the wrong way?defined(my $pid = fork) or die "Can't fork: $!\n"; exit if $pid; setsid or die "Can't start a new session: $!\n"; + + $SIG{'HUP'} = $SIG{'INT'} = $SIG{'KILL'} = $SIG{'TERM'} = &sig_handler +; my $connection_log = "/var/log/qmail/qmail-smtpd/current"; if(-e $connection_log){ my $file = File::Tail->new($connection_log); my $line; while (defined($line = $file->read)) { print "Line contents: $line\n"; } } sub sig_handler { my $sig = shift; print "Received SIG $sig\n"; quit(0); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: fork process + SIG handlers
by tachyon (Chancellor) on Dec 04, 2004 at 00:00 UTC | |
by jdalbec (Deacon) on Dec 04, 2004 at 04:31 UTC | |
by tachyon (Chancellor) on Dec 04, 2004 at 23:36 UTC | |
Re: fork process + SIG handlers
by rev_1318 (Chaplain) on Dec 03, 2004 at 23:21 UTC | |
Re: fork process + SIG handlers
by BUU (Prior) on Dec 04, 2004 at 05:01 UTC | |
Re: fork process + SIG handlers
by Zaxo (Archbishop) on Dec 04, 2004 at 04:22 UTC | |
by BUU (Prior) on Dec 04, 2004 at 04:58 UTC |
Back to
Seekers of Perl Wisdom