Hello
Paul J Stevens wrote:
> This is a long-standing issue. If anyone has any ideas I'd be happy to
> hear them.
perldoc -q daemon :
How do I fork a daemon process?
If by daemon process you mean one that's detached (disassociated from its
tty), then the following process is reported to work on most Unixish systems.
o Open /dev/tty and use the TIOCNOTTY ioctl on it. See tty for details. Or
better yet, you can just use the POSIX::setsid() function, so you don't
have to worry about process groups.
o Change directory to /
o Reopen STDIN, STDOUT, and STDERR so they're not connected to the old tty.
o Background yourself like this:
fork && exit;
And this is Proc::Daemon module (I think, this help you):
sub Fork {
my($pid);
FORK: {
if (defined($pid = fork)) {
return $pid;
} elsif ($! =~ /No more process/) {
sleep 5;
redo FORK;
} else {
croak "Can't fork: $!";
}
}
}
sub OpenMax {
my $openmax = POSIX::sysconf( &POSIX::_SC_OPEN_MAX );
(!defined($openmax) || $openmax < 0) ? 64 : $openmax;
}
sub Init {
my $oldmode = shift || 0;
my($pid, $sess_id, $i);
## Fork and exit parent
if ($pid = Fork) { exit 0; }
## Detach ourselves from the terminal
croak "Cannot detach from controlling terminal"
unless $sess_id = POSIX::setsid();
## Prevent possibility of acquiring a controling terminal
if (!$oldmode) {
$SIG{'HUP'} = 'IGNORE';
if ($pid = Fork) { exit 0; }
}
## Change working directory
chdir "/";
## Clear file creation mask
umask 0;
## Close open file descriptors
# May be close only STDIN STDOUT STDERR
foreach $i (0 .. OpenMax) { POSIX::close($i); }
## Reopen stderr, stdout, stdin to /dev/null
open(STDIN, "+>/dev/null");
open(STDOUT, "+>&STDIN");
open(STDERR, "+>&STDIN");
$oldmode ? $sess_id : 0;
}
> Marc Dirix wrote:
> > I've installed dbmail from svn over the debian rules script,
> >
> > The problem I think is, that one of the dbmail processes (lmtp or imap
> > I use both) doesn't completely detach from the console. Because after
> > starting dbmail from the init script I can't logout off the console
> > anymore.
--
Oleg Lapshin