DAEMON(8)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

🌸 DAEMON(8) β€” the daemon(8) page, bestie edition πŸ’…

okay so you picked up the daemon page from the System Manager's Manual and honestly? it's a gem. let's get into it ✨


✨ NAME ✨

daemon β€” run detached from the controlling terminal 🫢


πŸŽ€ SYNOPSIS πŸŽ€

daemon [-cfHrS] [-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 πŸ’–

So basically: the daemon utility detaches itself from the controlling terminal and then executes the program you specified in its arguments. main character energy fr β€” it just peaces out of your terminal and lives its own life. πŸ¦‹

Privileges may be lowered to the specified user. and the output of the daemonized process? you can redirect it to syslog and/or to a log file. iconic.

The options are as follows:

  • -C, --restart-count restart_count β€” restart the process at most restart_count times. if you pass zero, daemon will exit. the maximum restart count is 128. this option is used together with the --restart option (they're a package deal πŸ’œ).
  • -c, --change-dir β€” change the current working directory to the root ("/"). home is where the / is, i guess.
  • -f, --close-fds β€” redirect standard input, standard output and standard error to /dev/null. and listen: when you use this together with any of the options related to file or syslog output, the standard file descriptors get redirected to /dev/null first, and then stdout and/or stderr is redirected to a file or to syslog as specified by the other options. order matters, bestie πŸŽ€
  • -H, --sighup β€” close output_file and re-open it when the signal SIGHUP is received, for interoperability with newsyslog(8) and similar log rotation / archival mechanisms. that's the whole point β€” log rotation slay. if --output-file is not specified, this flag is just ignored (no cap, it does nothing πŸ™ˆ).
  • -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 the 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) 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's created with the default file mode. when this option is used together with the options --change-dir and --sighup, the absolute path needs to be provided to ensure daemon can re-open the file after a SIGHUP. so like… give it the full path or it's gonna fumble the re-open, no cap.
  • -P, --supervisor-pidfile 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 --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) 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. same vibe, different file 🫢
  • -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 β€” a whole year of patience, we love a committed queen).
  • -r, --restart β€” supervise and restart the program after a one-second delay if it has been terminated. short delay, big loyalty πŸ’–
  • -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. like, it wears its own name as a flex ✨
  • -u, --user user β€” login name of the user to execute the program under. the environment variables HOME, USER, and SHELL are set accordingly. requires adequate superuser privileges. πŸ”

okay, this next bit is important, so pay attention bestie:

if any of the options --child-pidfile, --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. and in this case, if the monitoring daemon receives the software termination signal (SIGTERM), it forwards it to the spawned process. normally that will cause the child to exit, remove the pidfile(s), and then terminate. 🧚

if neither file nor syslog output are selected, all output is redirected to the daemon process and written to stdout. and the --close-fds option may be used to suppress the stdout output completely. (silence. peace. πŸ’€)


also, the --supervisor-pidfile option is useful when combined with the --restart option, because supervisor_pidfile contains the ID of the supervisor, not the child. this is especially important if you use --restart in an rc script, because the --child-pidfile option will give you the child's ID to signal when you attempt to stop the service β€” which causes daemon to restart the child. 😭 like, you thought you stopped it. you did not stop it. it's giving "immortal".

⚠️ real talk: that pidfile mix-up is a classic. use --supervisor-pidfile with --restart. periodt.

⭐ EXIT STATUS ⭐

the daemon utility exits:

  1. 1 if an error is returned by the daemon(3) library routine
  2. 2 if child_pidfile or supervisor_pidfile is requested, but cannot be opened
  3. 3 if process is already running (pidfile exists and is locked)
  4. 4 if syslog_priority is not accepted
  5. 5 if syslog_facility is not accepted
  6. 6 if output_mask is not within the accepted range
  7. 7 if output_file cannot be opened for appending

and otherwise 0. slay πŸ’…


πŸ” 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. so like… where the error shows up is kind of a vibe check on your flags πŸŽ€


🌈 SEE ALSO 🌈

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


🌸 HISTORY 🌸

the daemon utility first appeared in FreeBSD 4.7. a legend was born ✨


and that's the whole page, bestie β€” go forth and daemonize responsibly πŸ«ΆπŸ’œ

mwah πŸ’‹ β€” this one's from the Debian crew, dated January 28, 2026. see u in the next manpage πŸŽ€

πŸ“¦ where this page comes from
  • freebsd 15.1: base 15.1
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms