1DAEMON(3) Linux Programmer's Manual DAEMON(3)
2
3
4
6 daemon - run in the background
7
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
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 process's current working
22 directory to the root directory ("/"); otherwise,
23
24 If noclose is zero, daemon() redirects standard input, standard output
25 and standard error to /dev/null; otherwise, no changes are made to
26 these file descriptors.
27
29 (This function forks, and if the fork(2) succeeds, the parent calls
30 _exit(2), so that further errors are seen by the child only.) On suc‐
31 cess daemon() returns zero. If an error occurs, daemon() returns -1
32 and sets errno to any of the errors specified for the fork(2) and set‐
33 sid(2).
34
36 Not in POSIX.1-2001. A similar function appears on the BSDs. The dae‐
37 mon() function first appeared in 4.4BSD.
38
40 The glibc implementation can also return -1 when /dev/null exists but
41 is not a character device with the expected major and minor numbers.
42 In this case errno need not be set.
43
45 fork(2), setsid(2)
46
48 This page is part of release 3.22 of the Linux man-pages project. A
49 description of the project, and information about reporting bugs, can
50 be found at http://www.kernel.org/doc/man-pages/.
51
52
53
54GNU 2009-05-02 DAEMON(3)