On Sun, 24 Nov 2002, Lee Nelson wrote: > myprogram.pl reads a few parameters from STDIN, and then > forks to work in the background: > > my $pid = fork; > exit if $pid; > die ("$pn couldn't fork $!\n") unless defined $pid; > POSIX::setsid() > or die ("$pn can't start a new session: $!\n"); > > Any clues or suggestions welcome.
The following method to daemonize a PERL process works for me in FreeBSD (I don't remember why I fork && exit twice, so don't ask): require 'sys/syscall.ph'; fork && exit; syscall(&SYS_setsid) || die "Can't call setsid(): $!"; chdir("/"); open(STDIN, "</dev/null") || die "Can't redirect stdin: $!"; open(STDOUT, ">/dev/null") || die "Can't redirect stdout: $!"; open(STDERR, ">/dev/null") || die "Can't redirect stderr: $!"; fork && exit; -- Chris Dillon - cdillon(at)wolves.k12.mo.us FreeBSD: The fastest and most stable server OS on the planet - Available for IA32 (Intel x86) and Alpha architectures - IA64, PowerPC, UltraSPARC, ARM, and S/390 under development - http://www.freebsd.org No trees were harmed in the composition of this message, although some electrons were mildly inconvenienced. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-questions" in the body of the message