Date: Mon, 25 Nov 2002 11:23:55 -0600 (CST) From: Chris Dillon <cdillon@wolves.k12.mo.us> To: Lee Nelson <jld123@pobox.com> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Apache not killing subprocesses, only on FreeBSD Message-ID: <20021125112037.W39486-100000@duey.wolves.k12.mo.us> In-Reply-To: <DAPNWVLH3Y2YJH5YPXHB4XZWECQKHB.3de075d8@lee>
next in thread | previous in thread | raw e-mail | index | archive | help
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 majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021125112037.W39486-100000>
