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