Re: deamonizing a program in Unix

From: Villy Kruse (vek_at_station02.ohout.pharmapartners.nl)
Date: 01/05/05


Date: 05 Jan 2005 09:13:59 GMT

On Tue, 04 Jan 2005 22:37:15 +0100,
    Måns Rullgård <mru@inprovide.com> wrote:

>
> It might be desirable to do some initial setup before daemonizing, so
> if something goes wrong, it can be easily reported. Many servers
> attempt to bind() a socket before becoming a deamon, and exit with an
> error code on failure.
>

You might still want to close all unwanted descriptors, but do that very
early in main() before opening sockets and other initial processing.
Perhaps you could leave stdout and stderr as is for error reporting during
start-up, and then later close and reopen stdout and stderr to /dev/null.

Villy



Relevant Pages