tail head cat sleep
QR code linking to this page

Manual Pages  — DAEMON

NAME

daemon – run detached from the controlling terminal

CONTENTS

SYNOPSIS


daemon [-cfrS] [-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] 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
  Change the current working directory to the root (" /").
-f
  Redirect standard input, standard output and standard error to /dev/null.
-S
  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.
-o output_file
  Append output from the daemonized process to output_file. If the file does not exist, it is created with permissions 0600.
-m 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.
-p 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 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 -u option is used or not.
-P supervisor_pidfile
  Write the ID of the daemon process into the supervisor_pidfile using the pidfile(3) 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 -u option is used or not.
-r
  Supervise and restart the program after a one-second delay if it has been terminated.
-R -restart_delay_seconds
  Supervise and restart the program after the specified delay if it has been terminated.
-t title
  Set the title for the daemon process. The default is the daemonized invocation.
-u user
  Login name of the user to execute the program under. Requires adequate superuser privileges.
-s syslog_priority
  These priorities are accepted: emerg, alert, crit, err, warning, notice, info, and debug. The default is info.
-l syslog_facility
  These facilities are accepted: auth, authpriv, console, cron, daemon, ftp, kern, lpr, mail, news, ntp, security, syslog, user, uucp, and local0, ..., local7. The default is daemon.
-T syslog_tag
  Set the tag which is appended to all syslog messages. The default is daemon.

If any of the options -p, -P, -r, -o, -s, -T, -m, -S, or -l 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 -f option may be used to suppress the stdout output completely.

The -P option is useful combined with the -r option as supervisor_pidfile contains the ID of the supervisor not the child. This is especially important if you use -r in an rc script as the -p 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 -f flag.

SEE ALSO

setregid(2), setreuid(2), daemon(3), exec(3), pidfile(3), termios(4), tty(4)

HISTORY

The daemon utility first appeared in FreeBSD 4.7 .

DAEMON (8) April 15, 2018

tail head cat sleep
QR code linking to this page


Please direct any comments about this manual page service to Ben Bullock.

An ASCII character walks into a bar and orders a double. "Having a bad day?" asks the barman. "Yeah, I have a parity error," replies the ASCII character. The barman says, "Yeah, I thought you looked a bit off."