3 .\" The Regents of the University of California. All rights reserved.
5 .\" SPDX-License-Identifier: BSD-4-Clause-UC
7 .\" @(#)daemon.3 8.1 (Berkeley) 6/9/93
8 .\" Added mentioning of glibc weirdness wrt unistd.h. 5/11/98, Al Viro
9 .TH daemon 3 (date) "Linux man-pages (unreleased)"
11 daemon \- run in the background
14 .RI ( libc ", " \-lc )
17 .B #include <unistd.h>
19 .BI "int daemon(int " nochdir ", int " noclose );
23 Feature Test Macro Requirements for glibc (see
24 .BR feature_test_macros (7)):
30 .\" commit 266865c0e7b79d4196e2cc393693463f03c90bd8
32 In glibc 2.19 and 2.20:
33 _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
34 Up to and including glibc 2.19:
35 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
40 function is for programs wishing to detach themselves from the
41 controlling terminal and run in the background as system daemons.
47 changes the process's current working directory
48 to the root directory ("/");
49 otherwise, the current working directory is left unchanged.
55 redirects standard input, standard output, and standard error
58 otherwise, no changes are made to these file descriptors.
60 (This function forks, and if the
62 succeeds, the parent calls
63 .\" not .IR in order not to underline _
65 so that further errors are seen by the child only.)
73 to any of the errors specified for the
78 For an explanation of the terms used in this section, see
84 Interface Attribute Value
89 T} Thread safety MT-Safe
93 A similar function appears on the BSDs.
95 The glibc implementation can also return \-1 when
97 exists but is not a character device with the expected
98 major and minor numbers.
107 The GNU C library implementation of this function was taken from BSD,
108 and does not employ the double-fork technique (i.e.,
112 that is necessary to ensure that the resulting daemon process is
113 not a session leader.
114 Instead, the resulting daemon
117 .\" FIXME . https://sourceware.org/bugzilla/show_bug.cgi?id=19144
118 .\" Tested using a program that uses daemon() and then opens an
119 .\" otherwise unused console device (/dev/ttyN) that does not
120 .\" have an associated getty process.
121 On systems that follow System V semantics (e.g., Linux),
122 this means that if the daemon opens a terminal that is not
123 already a controlling terminal for another session,
124 then that terminal will inadvertently become
125 the controlling terminal for the daemon.