daemon(1) β turns other processes into daemons.
| Use Case | Command | Description |
|---|---|---|
| Run a command as a daemon | daemon [options] -- cmd arg... |
Turn any command into a background daemon process. |
| Run a named daemon with autoβrestart | daemon --name mydaemon --respawn -- /path/to/command |
Ensure a single instance and respawn on failure. |
| Check if a named daemon is running | daemon --name mydaemon --running |
Exit with success if running, failure otherwise. |
| Stop a named daemon | daemon --name mydaemon --stop |
Send SIGTERM to the daemon and its client. |
| Restart a named daemonβs client | daemon --name mydaemon --restart |
Send SIGUSR1 to trigger a restart (requires --respawn). |
| List all named daemons | daemon --list |
Show currently running named daemons. |
| Run a daemon in foreground with pseudoβterminal | daemon --foreground --pty -- cmd |
Keep the client connected to a controlling terminal. |
| Run as a different user | daemon --user=user:group -- cmd |
Drop privileges (root only) before starting the client. |
usage: daemon [options] [--] [cmd arg...]
options:
-h, --help β Print a help message then exit-V, --version β Print a version message then exit-v, --verbose[=level] β Set the verbosity level-d, --debug[=level] β Set the debugging level-C, --config=path β Specify the system configuration file-N, --noconfig β Bypass the system configuration file-n, --name=name β Guarantee a single named instance-X, --command="cmd" β Specify the client command as an option-P, --pidfiles=/dir β Override standard pidfile location-F, --pidfile=/path β Override standard pidfile name and location-u, --user=user[:[group]] β Run the client as user[:group]-R, --chroot=path β Run the client with path as root-D, --chdir=path β Run the client in directory path-m, --umask=umask β Run the client with the given umask-e, --env="var=val" β Set a client environment variable-i, --inherit β Inherit environment variables-U, --unsafe β Allow execution of unsafe executable-S, --safe β Disallow execution of unsafe executable-c, --core β Allow core file generation--nocore β Disallow core file generation (default)-r, --respawn β Respawn the client when it terminates-a, --acceptable=# β Minimum acceptable client duration (seconds)-A, --attempts=# β Respawn # times on error before delay-L, --delay=# β Delay between respawn attempt bursts (seconds)-M, --limit=# β Maximum number of respawn attempt bursts--idiot β Idiot mode (trust root with the above)-f, --foreground β Run the client in the foreground-p, --pty[=noecho] β Allocate a pseudo terminal for the client-B, --bind β Stop when the user's last logind session ends-l, --errlog=spec β Send daemon's error output to syslog or file-b, --dbglog=spec β Send daemon's debug output to syslog or file-o, --output=spec β Send client's output to syslog or file-O, --stdout=spec β Send client's stdout to syslog or file-E, --stderr=spec β Send client's stderr to syslog or file--ignore-eof β After SIGCHLD ignore any client output--read-eof β After SIGCHLD read any client output (default)--running β Check if a named daemon is running--restart β Restart a named daemon client--stop β Terminate a named daemon process--signal=signame β Send a signal to a named daemon--list β Print a list of named daemonsdaemon(1) turns other processes into daemons. There are many tasks that need to be performed to correctly set up a daemon process. This can be tedious. daemon performs these tasks for other processes.
The preparatory tasks that daemon performs for other processes are:
--chroot option was supplied.--user option was supplied. Only root can use this option. Note that the uid of daemon itself is changed, rather than just changing the uid of the client process./etc/daemon.conf and /etc/daemon.conf.d/* by default, or specified by the --config option), unless the --noconfig option was supplied. Then read the user's personal configuration file(s) (~/.daemonrc and ~/.daemonrc.d/*), if any. Generic options that apply to all daemons are processed first, then options that are specific to the daemon with the given name. Note: The root directory and the user must be set before access to the configuration file(s) can be attempted, so neither the --chroot nor --user options may appear in the configuration file./usr/local/etc/daemon.conf and /usr/local/etc/daemon.conf.d/* by default./opt/local/etc/daemon.conf and /opt/local/etc/daemon.conf.d/*.--core option was supplied)./dev/null, in case something requires them to be open. Of course, this is not done if daemon was invoked by inetd(8).--name option was supplied, create and lock a file containing the process id of the daemon process. The presence of this locked file prevents two instances of a daemon with the same name from running at the same time. The default location of the pidfile is /var/run for root (/etc on Solaris, /opt/local/var/run on macOS when installed via macports), and /tmp for normal users. If the --pidfiles option was supplied, its argument specifies the directory in which the pidfile will be placed. If the --pidfile option was supplied, its argument specifies the name of the pidfile and the directory in which it will be placed.--umask option was supplied, set the umask to its argument, which must be a valid three-digit octal mode. Otherwise, set the umask to 022, to prevent clients from accidentally creating group- or world-writable files.--chdir option was supplied.--command option. If both the --command option and command line arguments are present, the client command is the result of appending the command line arguments to the argument of the --command option.--output, --stdout and/or --stderr options were supplied, the client's standard output and/or standard error are captured by daemon, and are sent to the respective syslog destinations.--respawn option was supplied. If the client ran for less than 300 seconds (or the value of the --acceptable option), then daemon sees this as a failure. It will attempt to restart the client up to five times (or the value of the --attempts option), before waiting for 300 seconds (or the value of the --delay option). This gives the system administrator the chance to correct whatever is preventing the client from running successfully without overloading system resources. If the --limit option was supplied, daemon terminates after the specified number of respawn attempt bursts. The default is zero, which means never give up, never surrender.--respawn option wasn't supplied, daemon terminates as well.--stop option), it propagates the signal to the client and then terminates.--restart option), it sends a SIGTERM signal to the client. If it was started with the --respawn option, the client process will be restarted after it is terminated by the SIGTERM signal.--foreground option was supplied, the client process is run as a foreground process, and is not turned into a daemon at all. If daemon is connected to a terminal, then the client process will also be connected to it. If daemon is not connected to a terminal, but the client needs to be connected to a terminal, use the --pty option.-h, --help β π‘ Display a help message and exit.-V, --version β βΉοΈ Display a version message and exit.-v[level], --verbose[=level] β π Set the message verbosity level to level (or 1 if level is not supplied). This only effects the --running and --list options.-d[level], --debug[=level] β π Set the debug message level to level (or 1 if level is not supplied). Level 1 traces high-level function calls. Level 2 traces lower-level function calls and shows configuration information. Level 3 adds environment variables. Level 9 adds every return value from select(2). Debug messages are sent to the destination specified by the --dbglog option (by default, the syslog(3) facility, daemon.debug).-C path, --config=path β βοΈ Specify the system configuration file to use. By default, /etc/daemon.conf is the system configuration file, if it exists and is not group- or world-writable, and does not exist in a group- or world-writable directory. The configuration file lets you predefine options that apply to all clients, and to specifically named clients./etc/daemon.conf.d). Any file in that directory whose name starts with a dot character (".") is ignored. The same checks as described above apply to these files as well./usr/local/etc/daemon.conf and /usr/local/etc/daemon.conf.d/* by default./opt/local/etc/daemon.conf and /opt/local/etc/daemon.conf.d/*.-N, --noconfig β π« Bypass the system configuration files, /etc/daemon.conf and /etc/daemon.conf.d/*. Only the user's ~/.daemonrc and ~/.daemonrc.d/* configuration files will be read (if they exist).-n name, --name=name β π·οΈ Create and lock a pidfile (name.pid), ensuring that only one daemon with the given name is active at the same time. The standard location of the pidfile is /var/run for root (/etc on Solaris, /opt/local/var/run on macOS when installed via macports), and /tmp for normal users. This location can be overridden with the --pidfiles option.-._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.clientpid rather than .pid.-X "cmd", --command="cmd" β π Specify the client command as an option. If a command is specified along with its name in the configuration file, then a daemon can be invoked merely by mentioning its name: daemon --name ftumch-P /dir, --pidfiles=/dir β π Override the standard pidfile location.-F /path, --pidfile=/path β π Override the standard pidfile name and location.-u user[:[group]], --user=user[:[group]] β π€ Run the client as a different user (and group). This only works for root. If the argument includes a :group specifier, daemon will assume the specified group and no other. Otherwise, daemon will assume all groups that the specified user is in.-R path, --chroot=path β π Change the root directory to path before running the client. On some systems, only root can do this. Note that the path to the client program and to the configuration file (if any) must be relative to the new root path.-D path, --chdir=path β π Change the current directory to path before running the client. The default current directory is the root directory (possibly after chroot).-m umask, --umask=umask β π’ Change the umask to umask before running the client. umask must be a valid octal mode. The default umask is 022.-e "var=val", --env="var=val" β π Set an environment variable for the client process. This option can be used any number of times. If it is used, only the supplied environment variables are passed to the client process. Otherwise, the client process inherits the current set of environment variables.-i, --inherit β π₯ Explicitly inherit environment variables. This is only needed when the --env option is used. When this option is used, the --env option adds to the inherited environment, rather than replacing it.-U, --unsafe β β οΈ Allow reading an unsafe configuration file, and allow the execution of an unsafe executable. A configuration file or executable is considered to be unsafe if it is group- or world-writable or is in a directory that is group- or world-writable (following symbolic links).-S, --safe β β
Disallow reading an unsafe configuration file, and disallow the execution of an unsafe executable.-c, --core β πΎ Allow the client to create a core file. This should only be used for debugging, as it could lead to security-related information disclosures by daemons run by root.--nocore β π« By default, clients are prevented from creating a core file. If the --core option has been used in a configuration file to apply to all named daemons, then this option can be used to restore the default behaviour for specific named daemons.-r, --respawn β π Respawn the client when it terminates. Without this option, the termination of a client process causes daemon itself to terminate as well.-a #, --acceptable=# β β±οΈ Specify the minimum acceptable duration of a client process, in seconds. This option can only be used with the --respawn option. If a client process terminates before this threshold is reached, then it is considered to have failed. The default value is 300 seconds. It cannot be set to less than 10 seconds, except by root when used in conjunction with the --idiot option.-A #, --attempts=# β π Specify the number of attempts to respawn before delaying. This option can only be used with the --respawn option. The default value is 5. It cannot be set to more than 100 attempts, except by root when used in conjunction with the --idiot option.-L #, --delay=# β β³ Specify the delay in seconds between each burst of respawn attempts. This option can only be used with the --respawn option. The default value is 300 seconds. It cannot be set to less than 10 seconds except by root when used in conjunction with the --idiot option.-M #, --limit=# β π’ Specify a limit to the number of respawn attempt bursts. This option can only be used with the --respawn option. The default value is 0, which means no limit.--idiot β π€ͺ Turn on idiot mode in which daemon will not enforce the minimum or maximum values normally imposed on the --acceptable, --attempts and --delay options. The --idiot option must appear before any of these options. Only the root user may use this option.-f, --foreground β π Run the client in the foreground. The client is not turned into a daemon.-p[noecho], --pty[=noecho] β π₯οΈ Connect the client to a pseudo terminal. This option can only be used with the --foreground option. This is the default when the --foreground option is supplied and daemon's standard input is connected to a terminal.-B, --bind β π Automatically terminate the client process (and daemon(1) itself) as soon as the user has no systemd-logind(8) (or elogind(8)) user sessions.-l spec, --errlog=spec β π Send daemon's standard output and standard error to the syslog destination or file that is specified by spec.-b spec, --dbglog=spec β π Send daemon's debug output to the syslog destination or file that is specified by spec.-o spec, --output=spec β π€ Capture the client's standard output and standard error, and send it to the syslog destination or file that is specified by spec.-O spec, --stdout=spec β π€ Capture the client's standard output, and send it to the syslog destination or file that is specified by spec.-E spec, --stderr=spec β π€ Capture the client's standard error, and send it to the syslog destination or file that is specified by spec.--ignore-eof β βοΈ After receiving a SIGCHLD signal, don't bother reading the client's output until the end-of-file is reached before reaping the client process's termination status.--read-eof β π After receiving a SIGCHLD signal, continue reading the client's output until the end-of-file is reached before reaping the client process's termination status. This is the default behaviour.--running β π Check whether or not a named daemon is running, then exit(3) with EXIT_SUCCESS if the named daemon is running or EXIT_FAILURE if it isn't.--restart β π Instruct a named daemon to terminate and restart its client process, by sending it a SIGUSR1 signal.--stop β π Stop a named daemon by sending it a SIGTERM signal.--signal=signame β π‘ Send the given signal to a named daemon's client process.--list β π Print a list of the currently running named daemons whose pidfiles are in the applicable pidfile directory.As with all other programs, a -- argument signifies the end of options. Any options that appear on the command line after -- are part of the client command.
Some simple shell-like expansion is performed internally on the arguments of the command line options with a text argument (but not the options with a numeric argument).
Environment variable notation, such as $VAR or ${VAR}, is expanded. Then user home directory notation, such as ~ or ~user, is expanded. File name expansion (i.e. globbing) is NOT performed internally. Neither are any of your login shell's other wonderful expansions. This is very basic.
This might not be of much use on the command line, since daemon is normally invoked via a shell, which will first perform all of its usual expansions. It might even be undesirable to perform expansion internally after the shell has already done so (e.g. if you refer to any directory names that actually contain the '$' character, or if you use any environment variables whose values contain the '$' character, which is unlikely).
But it can be useful in configuration files. See the FILES section below for more details. It can also be useful when daemon is invoked directly by another program without the use of a shell.
By default, environment variable expansion is not performed for the root user, even if the environment variable was defined in the configuration files. The --idiot option can be used to change this behaviour, and allow the expansion of environment variables for the root user. Home directory notation expansion is performed for all users.
/etc/daemon.conf, /etc/daemon.conf.d/* β system-wide default options/usr/local/etc/daemon.conf, /usr/local/etc/daemon.conf.d/* β system-wide default options on BSD systems (except macOS)./opt/local/etc/daemon.conf, /opt/local/etc/daemon.conf.d/* β system-wide default options on macOS when installed via macports.~/.daemonrc, ~/.daemonrc.d/* β user-specific default optionsEach line of the configuration file is either an environment variable definition, or a configuration directive.
Environment variable definitions consist of the variable name, followed immediately by '=' and the value of the variable. They look like they do in shell, except that there is no quoting or other shell syntax. Environment variable values can include simple environment variable notation (e.g. $VAR or ${VAR}), and user home directory notation (e.g. ~ or ~user). These will be expanded internally by daemon. See the EXPANSION section above for more details.
Note that any environment variables that are defined in the configuration file, which are subsequently used explicitly in another environment variable definition or in an option argument, will have these expansions performed multiple times. Avoid environment variables whose values can change again if expansion is performed multiple times.
Example:
PATH=/usr/bin:/usr/sbin:$HOME/bin:~app/bin
PIDFILES=~/.run
Configuration directives consist of a client name (for options that apply to a single client), or '*' (for generic options that apply to all clients), followed by spaces and/or tabs, followed by a comma-separated list of options. Any option arguments must not contain any commas. The commas that separate options can have spaces and tabs before and after them. Option arguments that are text (but not numbers) can include simple environment variable notation (e.g. $VAR or ${VAR}), and user home directory notation (e.g. ~ or ~user). These will be expanded internally by daemon. See the EXPANSION section above for more details.
Blank lines and comments ('#' to end of the line) are ignored. Lines can be continued with a '\' character at the end of the line.
Example:
* errlog=daemon.err,output=local0.err,core
test1 syslog=local0.debug,debug=9,verbose=9,respawn
test2 syslog=local0.debug,debug=9, \
verbose=9,respawn, \
pidfiles=$PIDFILES
The command line options are processed first, to look for a --config option. If no --config option was supplied, the default configuration files, /etc/daemon.conf and /etc/daemon.conf.d/*, are used. On BSD systems (except macOS), the default configuration files are /usr/local/etc/daemon.conf and /usr/local/etc/daemon.conf.d/*. On macOS when installed via macports, the default configuration files are /opt/local/etc/daemon.conf and /opt/local/etc/daemon.conf.d/*. If the user has their own configuration files, ~/.daemonrc and ~/.daemonrc.d/*, they are also used.
If the configuration files contain any generic ('*') entries, their options are applied in order of appearance. If the --name option was supplied, and the configuration files contain any entries for the given name, those options are then applied in order of appearance.
Finally, the command line options are applied again. This ensures that any generic options apply to all clients by default. Client-specific options override generic options. User options override system-wide options. Command line options override everything else.
Note that the configuration files are not opened and read until after any --chroot and/or --user command line options are processed. This means that the configuration file paths and the client's file path must be relative to the --chroot argument. It also means that the configuration files and the client executable must be readable/executable by the user specified by the --user argument. It also means that the --chroot and --user options must not appear in the configuration file. Also note that the --name option must not appear on the right hand side in the configuration file either.
The --errlog, --dbglog, --output, --stdout and --stderr options all take an argument that can be either a syslog destination of the form "facility.priority" or the path to a file. Here are the lists of syslog facilities and priorities:
kern, user, mail, daemon, auth, syslog, lpr, news, uucp, cron, local0, local1, local2, local3, local4, local5, local6, local7.emerg, alert, crit, err, warning, notice (on some systems), info, debug.If the path to a file is supplied instead, bear in mind the fact that daemon(1) changes to the root directory by default, and so the file path should be an absolute path (or relative to the --chroot and/or --chdir option argument). Otherwise, daemon(1) will attempt to create the file relative to its current directory. You might not have permissions to do that, or want to even if you do.
--respawn option. Using --restart on a non-respawning daemon client is equivalent to using --stop. If you try to restart a named daemon, and it stops instead, then it probably wasn't started with the --respawn option.DAEMON_INIT_EXIT_DELAY_MSEC to the number of milliseconds by which to delay (e.g., DAEMON_INIT_EXIT_DELAY_MSEC=400). Or you could just avoid using exec when starting KDE applications./etc/systemd/logind.conf (or /etc/elogind/logind.conf): KillUserProcesses=nolibslack(3), daemon(3), coproc(3), pseudo(3), init(8), inetd(8), fork(2), umask(2), setsid(2), chdir(2), chroot(2), setrlimit(2), setgid(2), setuid(2), setgroups(2), initgroups(3), syslog(3), kill(2), wait(2), systemd-logind(8), elogind(8)
20210304 raf <raf AT raf.org>
```Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-31 00:05 @216.73.217.152
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format