Using daemon from /etc/init.d/functions

Steve smorrey at gmail.com
Fri Mar 30 17:22:09 MDT 2007


It's really simple you just fork 2 times before entering the main
application loop, then let the parent forks die.

Look at it though, I think this may be a mistake.  Looks like it's
leaving one extra parent just hanging there, because it's not actually
for daemonizing, it's for multi process spawning.
I initially picked up this trick as a quick and dirty way of having a
single server process running that could launch more copies of itself
to handle load outside its realm.  For instance if I have a server
responsible for a certain set area in a 3D world say -1024,1024 and
player wants to leave that area, I needed a quick way to spawn a new
server to handle the area the player was walking into.  However I
didn't want umpteen million processes running empty zones, so doing a
double fork allowed me to detach the child servers from the main root
server, and when those zones emptied out the child process would die a
natural death.
Anyways for some reason I got that mixed up in my mind with Daemonizing.

On 3/30/07, Andrew Jorgensen <andrew.jorgensen at gmail.com> wrote:
> On 3/30/07, Steve <smorrey at gmail.com> wrote:
> > I dunno about redhat, but anything I've ever wanted to run as a
> > daemon, I'ld just do the double fork thing in code.
>
> Double fork?  I thought all you had to do was close the STD* file
> handles, fork, and setsid to detach from the process tree.
>
> I'm not one who would know, though, so I'm interested in this trick.
>
> /*
> PLUG: http://plug.org, #utah on irc.freenode.net
> Unsubscribe: http://plug.org/mailman/options/plug
> Don't fear the penguin.
> */
>



More information about the PLUG mailing list