daemon8
Run detached from the controlling terminal
Usage
daemon [-cfHrSx]
[-p
child_pidfile]
[-P
supervisor_pidfile]
[-t
title]
[-u
user]
[-m
output_mask]
[-o
output_file]
[-s
syslog_priority]
[-T
syslog_tag]
[-l
syslog_facility]
[-R
restart_delay_seconds]
[-C
restart_count]
command
arguments ...
Overview
The daemon utility detaches itself from the controlling terminal and executes the program specified by its arguments. Privileges may be lowered to the specified user. The output of the daemonized process may be redirected to syslog and to a log file.
The options are as follows:
-
-C, --restart-count restart_count -
Restart the process at most restart_count times. When zero is specified,
daemonwill exit. The maximum restart count is128. This option is used together with option--restart. -
-c, --change-dir -
Change the current working directory to the root (“/”).
-
-f, --close-fds -
Redirect standard input, standard output and standard error to /dev/null. When this option is used together with any of the options related to file or syslog output, the standard file descriptors are first redirected to /dev/null, then stdout and/or stderr is redirected to a file or to syslog as specified by the other options.
-
-H, --sighup -
Close output_file and re-open it when signal SIGHUP is received, for interoperability with newsyslog(8) and similar log rotation / archival mechanisms. If
--output-fileis not specified, this flag is ignored. -
-l, --syslog-facility syslog_facility -
These facilities are accepted:
auth,authpriv,console,cron,daemon,ftp,kern,lpr,mail,news,ntp,security,syslog,user,uucp, and local facilities fromlocal0tolocal7. The default isdaemon. -
-m, --output-mask output_mask -
Redirect output from the child process stdout (
1), stderr (2), or both (3). This value specifies what is sent to syslog and the log file. The default is3. -
-M, --output-file-mode mode -
Specify the file mode to use when creating the output_file. The mode is interpreted using chmod(1) style semantics. This option is useful when the daemonized process or external log collectors require group or world access to the output file. The default is
0600. -
-o, --output-file output_file -
Append output from the daemonized process to output_file. If the file does not exist, it is created with the default file mode. When this option is used together with options
--change-dirand--sighupthe absolute path needs to be provided to ensuredaemoncan re-open the file after a SIGHUP. -
-P, --supervisor-pidfile supervisor_pidfile -
Write the ID of the
daemonprocess into the supervisor_pidfile using the pidfile(3) functionality. The program is executed in a spawned child process while thedaemonwaits until it terminates to keep the supervisor_pidfile locked and removes it after the process exits. The supervisor_pidfile owner is the user who runs thedaemonregardless of whether the--useroption is used or not. -
-p, --child-pidfile child_pidfile -
Write the ID of the created process into the child_pidfile using the pidfile(3) functionality. The program is executed in a spawned child process while the
daemonwaits until it terminates to keep the child_pidfile locked and removes it after the process exits. The child_pidfile owner is the user who runs thedaemonregardless of whether the--useroption is used or not. -
-R, --restart-delay restart_delay_seconds -
Supervise and restart the program after the specified delay if it has been terminated. Valid values are 1-31536000 (up to 1 year).
-
-r, --restart -
Supervise and restart the program after a one-second delay if it has been terminated.
-
-S, --syslog -
Enable syslog output. This is implicitly applied if other syslog parameters are provided. The default values are daemon, notice, and daemon for facility, priority, and tag, respectively.
-
-s, --syslog-priority syslog_priority -
These priorities are accepted:
emerg,alert,crit,err,warning,notice,info, anddebug. The default isnotice. -
-T, --syslog-tag syslog_tag -
Set the tag which is appended to all syslog messages. The default is
daemon. -
-t, --title title -
Set the title for the daemon process. The default is the daemonized invocation.
-
-u, --user user -
Login name of the user to execute the program under. Environment variables HOME, USER, and SHELL are set accordingly. Requires adequate superuser privileges.
-
-x, --execute-only -
Do not supervise the child process when using
-p. This option is useful to run the given program as another user when su(1) can't be used but a file holding the pid is needed. The child_pidfile will not be locked and the contents may be silently truncated by a concurrent daemon(8) invocation.
If any of the options --child-pidfile (without --execute-only ), --output-mask, --restart, --restart-delay, --supervisor-pidfile, --syslog, --syslog-facility --syslog-priority, --syslog-tag, or --output, are specified, the program is executed in a spawned child process. The daemon waits until it terminates to keep the pid file(s) locked and removes them after the process exits or restarts the program. In this case if the monitoring daemon receives software termination signal (SIGTERM) it forwards it to the spawned process. Normally it will cause the child to exit, remove the pidfile(s) and then terminate.
If neither file or syslog output are selected, all output is redirected to the daemon process and written to stdout. The --close-fds option may be used to suppress the stdout output completely.
The --supervisor-pidfile option is useful combined with the --restart option as supervisor_pidfile contains the ID of the supervisor not the child. This is especially important if you use --restart in an rc script as the --child-pidfile option will give you the child's ID to signal when you attempt to stop the service, causing daemon to restart the child.
Exit status
The daemon utility exits 1 if an error is returned by the daemon(3) library routine, 2 if child_pidfile or supervisor_pidfile is requested, but cannot be opened, 3 if process is already running (pidfile exists and is locked), 4 if syslog_priority is not accepted, 5 if syslog_facility is not accepted, 6 if output_mask is not within the accepted range, 7 if output_file cannot be opened for appending, and otherwise 0.
Diagnostics
If the command cannot be executed, an error message is printed to standard error. The exact behavior depends on the logging parameters and the --close-fds flag.
Releases
61 releases since FreeBSD 4.7-RELEASE; the text changed 44 times.
- 4.7
- 4.8–4.11
- 5.0
- 5.1–5.2.1
- 5.3–5.5
- 6.0
- 6.1–6.3
- 6.4
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2
- 8.3
- 8.4
- 9.0
- 9.1
- 9.2
- 9.3
- 10.0
- 10.1
- 10.2
- 10.3
- 10.4
- 11.0
- 11.1
- 11.2
- 11.3
- 11.4
- 12.0
- 12.1
- 12.2
- 12.3
- 12.4
- 13.0–13.2
- 13.3–13.5
- 14.0
- 14.1–14.4
- 14.5
- 15.0
- 15.1
- 16.0
--change-dir since FreeBSD 13.3-RELEASE;
--child-pidfile since FreeBSD 13.3-RELEASE;
--close-fds since FreeBSD 13.3-RELEASE;
--execute-only since FreeBSD 16.0-CURRENT (2026-10-27);
--output-file since FreeBSD 13.3-RELEASE;
--output-file-mode since FreeBSD 15.1-RELEASE;
--output-mask since FreeBSD 13.3-RELEASE;
--restart since FreeBSD 13.3-RELEASE;
--restart-count since FreeBSD 15.0-RELEASE;
--restart-delay since FreeBSD 13.3-RELEASE;
--sighup since FreeBSD 13.3-RELEASE;
--supervisor-pidfile since FreeBSD 13.3-RELEASE;
--syslog since FreeBSD 13.3-RELEASE;
--syslog-facility since FreeBSD 13.3-RELEASE;
--syslog-priority since FreeBSD 13.3-RELEASE;
--syslog-tag since FreeBSD 13.3-RELEASE;
--title since FreeBSD 13.3-RELEASE;
--user since FreeBSD 13.3-RELEASE;
-C since FreeBSD 15.0-RELEASE;
-H since FreeBSD 12.3-RELEASE;
-M since FreeBSD 15.1-RELEASE;
-P since FreeBSD 9.3-RELEASE;
-R since FreeBSD 11.2-RELEASE;
-S since FreeBSD 11.1-RELEASE;
-T since FreeBSD 11.1-RELEASE;
-l since FreeBSD 11.1-RELEASE;
-m since FreeBSD 11.1-RELEASE;
-o since FreeBSD 11.1-RELEASE;
-p since FreeBSD 5.3-RELEASE;
-r since FreeBSD 9.1-RELEASE;
-s since FreeBSD 11.1-RELEASE;
-t since FreeBSD 11.0-RELEASE;
-u since FreeBSD 7.0-RELEASE;
-x since FreeBSD 16.0-CURRENT (2026-10-27).
-restart_delay_seconds until FreeBSD 11.4-RELEASE.