---
name: "daemon"
section: "8"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/daemon/8"
---

# daemon(8)

run detached from the controlling terminal

## NAME

**daemon** – run detached from the controlling terminal

## SYNOPSIS

**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* *...*

## DESCRIPTION

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, **daemon** will exit. The maximum restart count is **128**. 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)](/newsyslog/8.md) and similar log rotation / archival mechanisms. If **--output-file** is 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 from **local0** to **local7**. The default is **daemon**.

- **-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 is **3**.

- **-M**, **--output-file-mode** *mode*

  Specify the file *mode* to use when creating the *output\_file*. The mode is interpreted using [chmod(1)](/chmod/1.md) 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-dir** and **--sighup** the absolute path needs to be provided to ensure **daemon** can re-open the file after a SIGHUP.

- **-P**, **--supervisor-pidfile** *supervisor\_pidfile*

  Write the ID of the **daemon** process into the *supervisor\_pidfile* using the [pidfile(3)](/pidfile/3.md) functionality. The program is executed in a spawned child process while the **daemon** waits 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 the **daemon** regardless of whether the **--user** option is used or not.

- **-p**, **--child-pidfile** *child\_pidfile*

  Write the ID of the created process into the *child\_pidfile* using the [pidfile(3)](/pidfile/3.md) functionality. The program is executed in a spawned child process while the **daemon** waits 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 the **daemon** regardless of whether the **--user** option 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**, and **debug**. The default is **notice**.

- **-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)](/su/1.md) 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)](/daemon/8.md) 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)](/daemon/3.md) 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.

## SEE ALSO

[nohup(1)](/nohup/1.md), [setregid(2)](/setregid/2.md), [setreuid(2)](/setreuid/2.md), [daemon(3)](/daemon/3.md), [exec(3)](/exec/3.md), [pidfile(3)](/pidfile/3.md), [termios(4)](/termios/4.md), [tty(4)](/tty/4.md)

## HISTORY

The **daemon** utility first appeared in FreeBSD 4.7.
