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

Lowell Gilbert freebsd-questions-local at be-well.ilk.org
Wed Dec 4 23:01:31 UTC 2013

Unga <unga888 at yahoo.com> writes:

> 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 .

You have to realize that in saying that, DJB is using his own
definitions of multiple terms, subtly different from the usual
senses of those words. You have to be aware that you're dealing 
with someone who goes his own way in order to make progress with
his approaches to things.

> That is, is it possible to write a daemon to run in foreground and automatically started at system boot up (via /etc/rc.conf)?

Note that rc.conf doesn't actually do anything by itself. It contains
only settings that other scripts will use for configuring various
settings. I will assume that when you say "rc.conf" you mean the whole
system, with scripts in rc.d and so forth.

In which case, the answer is still "not directly"; if you want to, you
would install daemontools and use that to start the program in

> 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?

No. As I understand it, the idea is that there's no fork needed at all,
because the program invocation blocks and remains the process leader. 

> 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.

To be honest, I suspect you don't really have the background to
understand what daemontools is supposed to do for you. Most daemons
*only* fork in order to background themselves.

Good luck.

More information about the freebsd-questions mailing list