]>
Commit | Line | Data |
---|---|---|
a1eaacb1 | 1 | '\" t |
fea681da MK |
2 | .\" Copyright (c) 1993 |
3 | .\" The Regents of the University of California. All rights reserved. | |
4 | .\" | |
47009d5e | 5 | .\" SPDX-License-Identifier: BSD-4-Clause-UC |
fea681da MK |
6 | .\" |
7 | .\" @(#)daemon.3 8.1 (Berkeley) 6/9/93 | |
8 | .\" Added mentioning of glibc weirdness wrt unistd.h. 5/11/98, Al Viro | |
4c1c5274 | 9 | .TH daemon 3 (date) "Linux man-pages (unreleased)" |
fea681da MK |
10 | .SH NAME |
11 | daemon \- run in the background | |
b813014f AC |
12 | .SH LIBRARY |
13 | Standard C library | |
14 | .RI ( libc ", " \-lc ) | |
fea681da | 15 | .SH SYNOPSIS |
4653ec6e | 16 | .nf |
fea681da | 17 | .B #include <unistd.h> |
c6d039a3 | 18 | .P |
fea681da | 19 | .BI "int daemon(int " nochdir ", int " noclose ); |
4653ec6e | 20 | .fi |
c6d039a3 | 21 | .P |
d39ad78f | 22 | .RS -4 |
cc4615cc MK |
23 | Feature Test Macro Requirements for glibc (see |
24 | .BR feature_test_macros (7)): | |
d39ad78f | 25 | .RE |
c6d039a3 | 26 | .P |
cc4615cc | 27 | .BR daemon (): |
2c767761 | 28 | .nf |
d0544534 MK |
29 | Since glibc 2.21: |
30 | .\" commit 266865c0e7b79d4196e2cc393693463f03c90bd8 | |
31 | _DEFAULT_SOURCE | |
32 | In glibc 2.19 and 2.20: | |
5c10d2c5 | 33 | _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500) |
d0544534 | 34 | Up to and including glibc 2.19: |
5c10d2c5 | 35 | _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500) |
d0544534 | 36 | .fi |
fea681da MK |
37 | .SH DESCRIPTION |
38 | The | |
39 | .BR daemon () | |
40 | function is for programs wishing to detach themselves from the | |
41 | controlling terminal and run in the background as system daemons. | |
c6d039a3 | 42 | .P |
5a76509a | 43 | If |
fea681da | 44 | .I nochdir |
5a76509a | 45 | is zero, |
fea681da | 46 | .BR daemon () |
614e5d13 | 47 | changes the process's current working directory |
5a76509a | 48 | to the root directory ("/"); |
51a492bd | 49 | otherwise, the current working directory is left unchanged. |
c6d039a3 | 50 | .P |
5a76509a | 51 | If |
fea681da | 52 | .I noclose |
5a76509a | 53 | is zero, |
fea681da | 54 | .BR daemon () |
3d81c05a | 55 | redirects standard input, standard output, and standard error |
c9942389 MK |
56 | to |
57 | .IR /dev/null ; | |
5a76509a | 58 | otherwise, no changes are made to these file descriptors. |
47297adb | 59 | .SH RETURN VALUE |
fea681da | 60 | (This function forks, and if the |
fb186734 | 61 | .BR fork (2) |
9fe10273 | 62 | succeeds, the parent calls |
fea681da | 63 | .\" not .IR in order not to underline _ |
d4fdff35 | 64 | .BR _exit (2), |
fea681da | 65 | so that further errors are seen by the child only.) |
7e05b05e MK |
66 | On success |
67 | .BR daemon () | |
68 | returns zero. | |
fea681da MK |
69 | If an error occurs, |
70 | .BR daemon () | |
28d03ce9 | 71 | returns \-1 and sets |
fea681da | 72 | .I errno |
db4bf819 | 73 | to any of the errors specified for the |
fea681da | 74 | .BR fork (2) |
c13182ef | 75 | and |
fea681da | 76 | .BR setsid (2). |
be63524e | 77 | .SH ATTRIBUTES |
dce3395b MK |
78 | For an explanation of the terms used in this section, see |
79 | .BR attributes (7). | |
80 | .TS | |
81 | allbox; | |
c466875e | 82 | lbx lb lb |
dce3395b MK |
83 | l l l. |
84 | Interface Attribute Value | |
85 | T{ | |
9e54434e BR |
86 | .na |
87 | .nh | |
be63524e | 88 | .BR daemon () |
dce3395b MK |
89 | T} Thread safety MT-Safe |
90 | .TE | |
4131356c | 91 | .SH VERSIONS |
2b2581ee | 92 | A similar function appears on the BSDs. |
c6d039a3 | 93 | .P |
fea681da MK |
94 | The glibc implementation can also return \-1 when |
95 | .I /dev/null | |
96 | exists but is not a character device with the expected | |
c13182ef | 97 | major and minor numbers. |
e787ab6d | 98 | In this case, |
fea681da MK |
99 | .I errno |
100 | need not be set. | |
4131356c AC |
101 | .SH STANDARDS |
102 | None. | |
103 | .SH HISTORY | |
104 | 4.4BSD. | |
630551b9 MK |
105 | .SH BUGS |
106 | The GNU C library implementation of this function was taken from BSD, | |
107 | and does not employ the double-fork technique (i.e., | |
108 | .BR fork (2), | |
109 | .BR setsid (2), | |
110 | .BR fork (2)) | |
111 | that is necessary to ensure that the resulting daemon process is | |
112 | not a session leader. | |
113 | Instead, the resulting daemon | |
114 | .I is | |
115 | a session leader. | |
dbbdefa5 | 116 | .\" FIXME . https://sourceware.org/bugzilla/show_bug.cgi?id=19144 |
630551b9 MK |
117 | .\" Tested using a program that uses daemon() and then opens an |
118 | .\" otherwise unused console device (/dev/ttyN) that does not | |
119 | .\" have an associated getty process. | |
120 | On systems that follow System V semantics (e.g., Linux), | |
121 | this means that if the daemon opens a terminal that is not | |
122 | already a controlling terminal for another session, | |
123 | then that terminal will inadvertently become | |
124 | the controlling terminal for the daemon. | |
47297adb | 125 | .SH SEE ALSO |
e37e3282 | 126 | .BR fork (2), |
8f7a89b0 | 127 | .BR setsid (2), |
940bdd7e | 128 | .BR daemon (7), |
8f7a89b0 | 129 | .BR logrotate (8) |