Having every daemon put itself into the background is bad software design

Luca Ferrari fluca1978 at infinito.it
Thu Dec 5 15:13:03 UTC 2013


On Tue, Dec 3, 2013 at 6:38 PM, Unga <unga888 at yahoo.com> wrote:

> Dr. D. J. Bernstein says "Having every daemon put itself into the background
> is bad software design." in http://cr.yp.to/daemontools/faq/create.html .
>

Even having to configure or send to background every daemon by your
own is a bad design. I suspect the key point here is that every
daemon, before going to the background, should allow the admin to keep
it on the foregorund for very specific debugging purposes.


> Can someone provide a sample in C?
>

Yes:

int main( int argc, char** argv ){
    for ( ;; )
      printf( "\nI'm still here!" );
}

> Does he means after fork(2), the parent continue to run? Can such a program started via the /etc/rc.conf without a terminal attached?


After fork(2) the parent continues to run, effectively the parent and
the child run. What normally happens in a shell is that when you use
"&" to put a command in background the shell do not waits and continue
running on its own life.



> Btw, I got in to this problem by trying to use DJB's daemontools to supervise my server running on FreeBSD. But it creates zombie processes and spawn quite fast. In my daemons, after fork(2), parent returns.

I don't have any idea what you are doing, since it is not clear what
your daemons are doing....

Luca


More information about the freebsd-questions mailing list