1DAEMON(3)                  Linux Programmer's Manual                 DAEMON(3)
2
3
4

NAME

6       daemon - run in the background
7

SYNOPSIS

9       #include <unistd.h>
10
11       int daemon(int nochdir, int noclose);
12
13   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
14
15       daemon(): _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
16

DESCRIPTION

18       The daemon() function is for programs wishing to detach themselves from
19       the controlling terminal and run in the background as system daemons.
20
21       If nochdir is zero, daemon()  changes  the  calling  process's  current
22       working  directory  to the root directory ("/"); otherwise, the current
23       working directory is left unchanged.
24
25       If noclose is zero, daemon() redirects standard input, standard  output
26       and  standard  error  to  /dev/null;  otherwise, no changes are made to
27       these file descriptors.
28

RETURN VALUE

30       (This function forks, and if the fork(2)  succeeds,  the  parent  calls
31       _exit(2),  so that further errors are seen by the child only.)  On suc‐
32       cess daemon() returns zero.  If an error occurs,  daemon()  returns  -1
33       and  sets errno to any of the errors specified for the fork(2) and set‐
34       sid(2).
35

CONFORMING TO

37       Not in POSIX.1-2001.  A similar function appears on the BSDs.  The dae‐
38       mon() function first appeared in 4.4BSD.
39

NOTES

41       The  glibc  implementation can also return -1 when /dev/null exists but
42       is not a character device with the expected major  and  minor  numbers.
43       In this case errno need not be set.
44

SEE ALSO

46       fork(2), setsid(2)
47

COLOPHON

49       This  page  is  part of release 3.53 of the Linux man-pages project.  A
50       description of the project, and information about reporting  bugs,  can
51       be found at http://www.kernel.org/doc/man-pages/.
52
53
54
55GNU                               2009-12-05                         DAEMON(3)
Impressum