Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Nov 2002 02:10:30 +0100
From:      Mark <admin@asarian-host.net>
To:        "Chris Dillon" <cdillon@wolves.k12.mo.us>, "Lee Nelson" <jld123@pobox.com>
Cc:        <freebsd-questions@freebsd.org>
Subject:   Re: Apache not killing subprocesses, only on FreeBSD
Message-ID:  <200211260110.GAQ1AAI81189@asarian-host.net>
References:  <20021125112037.W39486-100000@duey.wolves.k12.mo.us>

next in thread | previous in thread | raw e-mail | index | archive | help
----- Original Message -----
From: "Chris Dillon" <cdillon@wolves.k12.mo.us>
To: "Lee Nelson" <jld123@pobox.com>
Cc: <freebsd-questions@FreeBSD.ORG>
Sent: Monday, November 25, 2002 6:23 PM
Subject: Re: Apache not killing subprocesses, only on FreeBSD


> On Sun, 24 Nov 2002, Lee Nelson wrote:
>
> > myprogram.pl reads a few parameters from STDIN, and then
> > forks to work in the background:


I daemonize as follows:

chdir ('/') || exit 1;
open STDIN, '/dev/null';
open STDOUT, '>/dev/null';
if (my $pid = fork ()) {
    open (PID, '>/var/run/my-prog.pid') || exit 1;
    flock (PID, 2);
    print PID "$pid";
    close (PID);
    exit 0;
}

POSIX::setsid () || exit 1;        # follow the leader
open STDERR, '>&STDOUT';

Guaranteed to become the session leader, and completely dissociates from the
terminal.

- Mark


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?200211260110.GAQ1AAI81189>