Re: Trouble writing background-running program



Carlos Moreno schrieb:

Carlos,

I of course tried to code the program to work as a daemon, following
the little
recipe and explanations from Stevens' Advanced Programming in the
Unix
Environment (1993 edition) --- I fork, close the parent, then in the
child I call
setsid() ... I skip the rest since my program changes to its "native"
directory
anyway, and it never creates files or directories, so the umask part
is also
unneeded).

does your code execute also the second fork() after setsid(), which is
essential to detach from the terminal properly?

As I recall there is an example code function "daemon_init()" which you
could simply copy and paste for your project.

Guido

--
http://www.bayernline.de/~gscholz/
http://www.lug-burghausen.org/
.



Relevant Pages

  • Daemon doubt.
    ... I'm currently writing a daemon process running on Linux. ... double-forkand setsid() and then chdirand then close the std ... has no more controlling terminal, then after the second fork(), the ... the second forkAND before the std fds closing, ...
    (comp.unix.programmer)
  • Re: How to "daemonize"?
    ... > 1) fork() ... > 2) setsid() ... > 6) close stdin, stdout, stderr ... continues as the daemon. ...
    (comp.os.linux.development.apps)
  • Re: daemons, sockets and ssh
    ... setsid - it's not just a C function anymore, ... redirect all your input to come from a file, ... succeed, fork and exit, and have the child do setsid. ... will also orphan the session and thus ensure the daemon and all it ...
    (comp.unix.shell)
  • one more Q on FAQs example
    ... Regarding daemon sample code in FAQ. ... Then old descriptors are closed. ...
    (comp.unix.programmer)