RE: writting a Daemon in c
> I am writting a Daemon in c, I need to know how to disconnect the program
> from the terminal so that if that terminal is destoyed it will not cause
> my server to shutdown. I have done this with perl scripts, but can't not
> figure it out with c. Thanks in advance
>
> Evan.
>
There is a very good reference to this in "Unix Network
Programming Vol 1" by W. Richard Stevens. Basically:
fork - parent exit
setsid - become session leader
signal - turn off SIGHUP
fork - parent exit (so this process is not a session leader)
umask - reset umask if you need to
close - flush and close all file descriptors
Then you open any files you need to, etc... There may
be a few more things you might want to reset (like a
bunch of signal handlers, etc.).
jim
Reply to: