OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / original / man3 / daemon.3
1 .\" Copyright (c) 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\"    must display the following acknowledgement:
15 .\"     This product includes software developed by the University of
16 .\"     California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\"    may be used to endorse or promote products derived from this software
19 .\"    without specific prior written permission.
20 .\"
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" SUCH DAMAGE.
32 .\" %%%LICENSE_END
33 .\"
34 .\"     @(#)daemon.3    8.1 (Berkeley) 6/9/93
35 .\" Added mentioning of glibc weirdness wrt unistd.h. 5/11/98, Al Viro
36 .TH DAEMON 3 2013-10-28 "GNU" "Linux Programmer's Manual"
37 .SH NAME
38 daemon \- run in the background
39 .SH SYNOPSIS
40 .B #include <unistd.h>
41 .sp
42 .BI "int daemon(int " nochdir ", int " noclose );
43 .sp
44 .in -4n
45 Feature Test Macro Requirements for glibc (see
46 .BR feature_test_macros (7)):
47 .in
48 .sp
49 .BR daemon ():
50 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500)
51 .SH DESCRIPTION
52 The
53 .BR daemon ()
54 function is for programs wishing to detach themselves from the
55 controlling terminal and run in the background as system daemons.
56 .PP
57 If
58 .I nochdir
59 is zero,
60 .BR daemon ()
61 changes the calling process's current working directory
62 to the root directory ("/");
63 otherwise, the current working directory is left unchanged.
64 .PP
65 If
66 .I noclose
67 is zero,
68 .BR daemon ()
69 redirects standard input, standard output and standard error
70 to
71 .IR /dev/null ;
72 otherwise, no changes are made to these file descriptors.
73 .SH RETURN VALUE
74 (This function forks, and if the
75 .BR fork (2)
76 succeeds, the parent calls
77 .\" not .IR in order not to underline _
78 .BR _exit (2),
79 so that further errors are seen by the child only.)
80 On success
81 .BR daemon ()
82 returns zero.
83 If an error occurs,
84 .BR daemon ()
85 returns \-1 and sets
86 .I errno
87 to any of the errors specified for the
88 .BR fork (2)
89 and
90 .BR setsid (2).
91 .SH ATTRIBUTES
92 .SS Multithreading (see pthreads(7))
93 The
94 .BR daemon ()
95 function is thread-safe.
96 .SH CONFORMING TO
97 Not in POSIX.1-2001.
98 A similar function appears on the BSDs.
99 The
100 .BR daemon ()
101 function first appeared in 4.4BSD.
102 .SH NOTES
103 The glibc implementation can also return \-1 when
104 .I /dev/null
105 exists but is not a character device with the expected
106 major and minor numbers.
107 In this case,
108 .I errno
109 need not be set.
110 .SH SEE ALSO
111 .BR fork (2),
112 .BR setsid (2)
113 .SH COLOPHON
114 This page is part of release 3.79 of the Linux
115 .I man-pages
116 project.
117 A description of the project,
118 information about reporting bugs,
119 and the latest version of this page,
120 can be found at
121 \%http://www.kernel.org/doc/man\-pages/.