Re: writting a Daemon in c
On Wed, Oct 20, 1999 at 10:35:51AM -0400, Evan Moore <[EMAIL PROTECTED]> wrote: > 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 man 3 daemon -- Eric Gillespie, Jr. <*> [EMAIL PROTECTED] "Man is a rope, tied between beast and overman--a rope over an abyss. A dangerous across, a dangerous on-the-way, a dangerous looking-back, a dangerous shuddering and stopping." --Friedrich Nietzsche pgpavdmpHWjJD.pgp Description: PGP signature
Re: writting a Daemon in c
On Wed, 20 Oct 1999, Evan Moore wrote: > > 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. > man daemon DAEMON(3) Linux Programmer's Manual DAEMON(3) NAME daemon - run in the background SYNOPSIS #include int daemon (int nochdir, int noclose); DESCRIPTION The daemon() function is for programs wishing to detach themselves from the controlling terminal and run in the background as system daemons. that's from potato OK
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
Re: writting a Daemon in c
On Wed, 20 Oct 1999, Evan Moore wrote: > 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 Use fork() to fork your daemon process. Exit the main process and have the child process perform the daemon functions. The child process will not exit when the controlling tty is gone. T