Subject: Re: how to write a Daemon process
To: John Sconiers <jrs@enteract.com>
From: Perry E. Metzger <perry@piermont.com>
List: netbsd-help
Date: 01/30/1999 00:00:08
John Sconiers <jrs@enteract.com> writes:
> Looking for information on how to write a Daemon process.  Is there a
> simple Daemon that has easy to follow code so i could grab the source
> and learn.  I know apache and sendmail as well as others use daemon's but
> i fear they may be to difficult for a beginner to decipher how to make a
> daemon process himself.

"What do you want to know"? Daemons are just processes like any other
process. The only thing special about daemons is that they detach from
the controlling terminal -- otherwise there is nothing special about
them. Just fork twice, close all your file descriptors (or, better
yet, turn fd 0, 1 and 2 into /dev/null) and do a setsid() to remove
yourself from the old process group you were in. I believe there is
now a utility function for this, but you should learn what it does
rather than using it blindly if you are this new at things.

Perry