]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - usr.sbin/daemon/daemon.8
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / usr.sbin / daemon / daemon.8
1 .\" Copyright (c) 1999 Berkeley Software Design, Inc. All rights reserved.
2 .\"
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
5 .\" are met:
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\"    notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\"    notice, this list of conditions and the following disclaimer in the
10 .\"    documentation and/or other materials provided with the distribution.
11 .\" 3. Berkeley Software Design Inc's name may not be used to endorse or
12 .\"    promote products derived from this software without specific prior
13 .\"    written permission.
14 .\"
15 .\" THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED.  IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 .\" SUCH DAMAGE.
26 .\"
27 .\" $FreeBSD$
28 .\"
29 .Dd June 4, 2012
30 .Dt DAEMON 8
31 .Os
32 .Sh NAME
33 .Nm daemon
34 .Nd run detached from the controlling terminal
35 .Sh SYNOPSIS
36 .Nm
37 .Op Fl cfr
38 .Op Fl p Ar pidfile
39 .Op Fl u Ar user
40 .Ar command arguments ...
41 .Sh DESCRIPTION
42 The
43 .Nm
44 utility detaches itself from the controlling terminal and
45 executes the program specified by its arguments.
46 Privileges may be lowered to the specified user.
47 .Pp
48 The options are as follows:
49 .Bl -tag -width indent
50 .It Fl c
51 Change the current working directory to the root
52 .Pq Dq Pa / .
53 .It Fl f
54 Redirect standard input, standard output and standard error to
55 .Pa /dev/null .
56 .It Fl p Ar file
57 Write the ID of the created process into the
58 .Ar file
59 using the
60 .Xr pidfile 3
61 functionality.
62 The program is executed in a spawned child process while the
63 .Nm
64 waits until it terminates to keep the
65 .Ar file
66 locked and removes it after the process exits.
67 The
68 .Ar file
69 owner is the user who runs the
70 .Nm
71 regardless of whether the
72 .Fl u
73 option is used or not.
74 .It Fl r
75 Supervise and restart the program if it has been terminated.
76 .It Fl u Ar user
77 Login name of the user to execute the program under.
78 Requires adequate superuser privileges.
79 .El
80 .Pp
81 If the
82 .Fl p
83 or
84 .Fl r
85 option is specified the program is executed in a spawned child process.
86 The
87 .Nm
88 waits until it terminates to keep the pid file locked and removes it
89 after the process exits or restarts the program.
90 In this case if the monitoring
91 .Nm
92 receives software termination signal (SIGTERM) it forwards it to the
93 spawned process.
94 Normally it will cause the child to exit followed by the termination
95 of the supervising process after removing the pidfile.
96 .Sh EXIT STATUS
97 The
98 .Nm
99 utility exits 1 if an error is returned by the
100 .Xr daemon 3
101 library routine, 2 if the
102 .Ar pidfile
103 is requested, but cannot be opened, 3 if process is already running (pidfile
104 exists and is locked),
105 otherwise 0.
106 .Sh DIAGNOSTICS
107 If the command cannot be executed, an error message is displayed on
108 standard error unless the
109 .Fl f
110 flag is specified.
111 .Sh SEE ALSO
112 .Xr setregid 2 ,
113 .Xr setreuid 2 ,
114 .Xr daemon 3 ,
115 .Xr exec 3 ,
116 .Xr pidfile 3 ,
117 .Xr termios 4 ,
118 .Xr tty 4
119 .Sh HISTORY
120 The
121 .Nm
122 utility first appeared in
123 .Fx 4.7 .