From owner-freebsd-questions Mon Nov 25 9:24: 4 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CD65537B401 for ; Mon, 25 Nov 2002 09:24:02 -0800 (PST) Received: from testmail.wolves.k12.mo.us (testmail.wolves.k12.mo.us [207.160.214.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3C20543EAF for ; Mon, 25 Nov 2002 09:24:02 -0800 (PST) (envelope-from cdillon@wolves.k12.mo.us) Received: by testmail.wolves.k12.mo.us (Postfix, from userid 1001) id 41A16CD19; Mon, 25 Nov 2002 11:23:55 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by testmail.wolves.k12.mo.us (Postfix) with ESMTP id 3CC0BCD18; Mon, 25 Nov 2002 11:23:55 -0600 (CST) Date: Mon, 25 Nov 2002 11:23:55 -0600 (CST) From: Chris Dillon To: Lee Nelson Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Apache not killing subprocesses, only on FreeBSD In-Reply-To: Message-ID: <20021125112037.W39486-100000@duey.wolves.k12.mo.us> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 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