DAEMON(8)
πΈ 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-countrestart_count β restart the process at most restart_count times. if you pass zero,daemonwill exit. the maximum restart count is 128. this option is used together with the--restartoption (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/nullfirst, 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 signalSIGHUPis received, for interoperability withnewsyslog(8)and similar log rotation / archival mechanisms. that's the whole point β log rotation slay. if--output-fileis not specified, this flag is just ignored (no cap, it does nothing π).-l,--syslog-facilitysyslog_facility β these facilities are accepted:auth,authpriv,console,cron,daemon,ftp,kern,lpr,mail,news,ntp,security,syslog,user,uucp, and the local facilities fromlocal0tolocal7. the default isdaemon.-m,--output-maskoutput_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-modemode β specify the file mode to use when creating the output_file. the mode is interpreted usingchmod(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 is0600. π₯-o,--output-fileoutput_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-dirand--sighup, the absolute path needs to be provided to ensuredaemoncan re-open the file after aSIGHUP. so likeβ¦ give it the full path or it's gonna fumble the re-open, no cap.-P,--supervisor-pidfilesupervisor_pidfile β write the ID of the daemon process into the supervisor_pidfile using thepidfile(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--useroption is used or not. π-p,--child-pidfilechild_pidfile β write the ID of the created process into the child_pidfile using thepidfile(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--useroption is used or not. same vibe, different file π«Ά-R,--restart-delayrestart_delay_seconds β supervise and restart the program after the specified delay if it has been terminated. valid values are1-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 aredaemon,notice, anddaemonfor facility, priority, and tag, respectively.-s,--syslog-prioritysyslog_priority β these priorities are accepted:emerg,alert,crit,err,warning,notice,info, anddebug. the default isnotice.-T,--syslog-tagsyslog_tag β set the tag which is appended to all syslog messages. the default isdaemon.-t,--titletitle β set the title for the daemon process. the default is the daemonized invocation. like, it wears its own name as a flex β¨-u,--useruser β login name of the user to execute the program under. the environment variablesHOME,USER, andSHELLare 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-pidfilewith--restart. periodt.
β EXIT STATUS β
the daemon utility exits:
1if an error is returned by thedaemon(3)library routine2if child_pidfile or supervisor_pidfile is requested, but cannot be opened3if process is already running (pidfile exists and is locked)4if syslog_priority is not accepted5if syslog_facility is not accepted6if output_mask is not within the accepted range7if 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
- Copyright (c) 1999 Berkeley Software Design, Inc. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms