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
14 The daemon() function is for programs wishing to detach themselves from
15 the controlling terminal and run in the background as system daemons.
16
17 Unless the argument nochdir is non-zero, daemon() changes the current
18 working directory to the root ("/").
19
20 Unless the argument noclose is non-zero, daemon() will redirect stan‐
21 dard input, standard output and standard error to /dev/null.
22
24 (This function forks, and if the fork() succeeds, the parent does
25 _exit(0), so that further errors are seen by the child only.) On suc‐
26 cess zero will be returned. If an error occurs, daemon() returns -1
27 and sets the global variable errno to any of the errors specified for
28 the library functions fork(2) and setsid(2).
29
31 fork(2), setsid(2)
32
34 The glibc implementation can also return -1 when /dev/null exists but
35 is not a character device with the expected major and minor numbers. In
36 this case errno need not be set.
37
39 Not in POSIX.1-2001. A similar function appears on the BSDs. The dae‐
40 mon() function first appeared in 4.4BSD.
41
42
43
44BSD MANPAGE 1993-06-09 DAEMON(3)