info > DAEMON(7)

DAEMON(1) User Commands DAEMON(1)

📖 NAME

daemon - turns other processes into daemons

🚀 Quick Reference

Use CaseCommandDescription
Run a command as a background daemondaemon [options] -- command arg...Run command in background as daemon with default settings
Run a named daemon with respawndaemon --name myapp -r -- commandEnsure only one instance, respawn on failure
Check if a named daemon is runningdaemon --name myapp --runningPrint status and exit code
Stop a named daemondaemon --name myapp --stopSend SIGTERM to daemon and its client
Restart a named daemondaemon --name myapp --restartSend SIGUSR1 to daemon to restart client
List all named daemonsdaemon --listShow all running named daemons
Run in foreground with pseudo-terminaldaemon -f -p commandRun client in foreground with a controlling terminal

🔖 SYNOPSIS

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 daemons

📝 DESCRIPTION

daemon(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:

⚙ïļ OPTIONS

-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 not supplied). This only affects the --running and --list options.

-d[level], --debug[=level] 🐛 Set the debug message level to level (or 1 if not supplied). Level 1 traces high-level function calls. Level 2 lower-level calls and configuration. Level 3 adds environment variables. Level 9 adds every return value from select(2). Debug messages are sent to the destination specified by --dbglog (default: syslog facility daemon.debug).

-C path, --config=path ⚙ïļ Specify the system configuration file to use. By default, /etc/daemon.conf. Additional files from /etc/daemon.conf.d/ are also read. On BSD systems (except macOS): /usr/local/etc/daemon.conf. On macOS via macports: /opt/local/etc/daemon.conf.

-N, --noconfig ðŸšŦ Bypass system configuration files. Only user's ~/.daemonrc and ~/.daemonrc.d/* are read.

-n name, --name=name 🏷ïļ Create and lock a pidfile (name.pid) ensuring only one daemon with the given name is active. The name may only consist of characters: -._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. While the client is running, a separate .clientpid file exists.

-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. Additional command line arguments are appended to the client command.

-P /dir, --pidfiles=/dir 📁 Override the standard pidfile location. The pidfile location will be created automatically only if it is within the user's home directory.

-F /path, --pidfile=/path 📄 Override the standard pidfile name and location. The pidfile location will be created automatically only if it is within the user's home directory.

-u user[:[group]], --user=user[:[group]] ðŸ‘Ī Run the client as a different user (and group). Only works for root. If the argument includes :group, daemon assumes the specified group and no other. Otherwise, assumes all groups the user is in. For backward compatibility, "." may be used instead of ":" but can cause ambiguities.

-R path, --chroot=path 🔒 Change the root directory to path before running the client. On some systems, only root can do this. Path to client and configuration file must be relative to the new root.

-D path, --chdir=path 📂 Change the current directory to path before running the client. Default is the root directory (possibly after chroot).

-m umask, --umask=umask 🔐 Change the umask to umask before running the client. Must be a valid octal mode. Default umask is 022.

-e "var=val", --env="var=val" 🌐 Set an environment variable for the client process. Can be used multiple times. If used, only supplied environment variables are passed to the client (unless --inherit is also used).

-i, --inherit 🔄 Explicitly inherit environment variables. This is only needed when --env is used. When used, --env adds to the inherited environment instead of replacing it.

-U, --unsafe ⚠ïļ Allow reading an unsafe configuration file and execution of an unsafe executable. A configuration file or executable is unsafe if it is group- or world-writable or in a directory that is group- or world-writable. By default, daemon refuses when run by root. This option should never be used.

-S, --safe ðŸ›Ąïļ Disallow reading an unsafe configuration file and execution of an unsafe executable. By default, daemon allows unsafe files when run by normal users. This option overrides that.

-c, --core ðŸ’ū Allow the client to create a core file. 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 --core has been used in a configuration file to apply to all named daemons, this option restores the default for specific named daemons.

-r, --respawn 🔄 Respawn the client when it terminates. Without this option, termination of the client causes daemon itself to terminate.

-a #, --acceptable=# ⏱ïļ Specify the minimum acceptable duration of a client process in seconds. Only used with --respawn. Default is 300 seconds. Cannot be set to less than 10 seconds, except by root with --idiot.

-A #, --attempts=# 🔄 Specify the number of attempts to respawn before delaying. Only used with --respawn. Default is 5. Cannot be set to more than 100, except by root with --idiot.

-L #, --delay=# âģ Specify the delay in seconds between each burst of respawn attempts. Only used with --respawn. Default is 300 seconds. Cannot be set to less than 10 seconds, except by root with --idiot.

-M #, --limit=# ðŸšĶ Specify a limit to the number of respawn attempt bursts. Only used with --respawn. Default is 0 (no limit).

--idiot ðŸĪŠ Turn on idiot mode in which daemon will not enforce the minimum or maximum values normally imposed on --acceptable, --attempts and --delay. The --idiot option must appear before any of these. Only root may use this option. Idiot mode also allows root to expand environment variable notation in command line option arguments and configuration files.

-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. Only used with --foreground. This is the default when --foreground is supplied and daemon's stdin is connected to a terminal. If noecho is supplied, the client's side of the pseudo terminal will be set to noecho mode.

-B, --bind 🔗 Automatically terminate the client process and daemon itself as soon as the user has no systemd-logind(8) (or elogind(8)) user sessions. Only available on Linux with systemd or elogind.

-l spec, --errlog=spec 📝 Send daemon's standard output and standard error to the syslog destination or file specified by spec. If spec is of the form "facility.priority", output is sent to syslog(3). Otherwise, appended to the file. Default: syslog destination daemon.err.

-b spec, --dbglog=spec 🐛 Send daemon's debug output to the syslog destination or file specified by spec. Default: syslog destination daemon.debug.

-o spec, --output=spec ðŸ“Ą Capture the client's standard output and standard error, and send to the syslog destination or file specified by spec. Default: discarded unless --foreground is present.

-O spec, --stdout=spec ðŸ“Ą Capture the client's standard output and send to the syslog destination or file specified by spec. Default: discarded unless --foreground is present.

-E spec, --stderr=spec ðŸ“Ą Capture the client's standard error and send to the syslog destination or file specified by spec. Default: discarded unless --foreground is present.

--ignore-eof ⏭ïļ After receiving SIGCHLD due to a stopped or restarted client process, don't read the client's output until EOF before reaping the client's termination status with wait(2). This prevents the client process from remaining as a zombie if its child processes keep the output open.

--read-eof 📖 After receiving SIGCHLD, continue reading the client's output until EOF before reaping the client's termination status. This is the default behaviour. If --ignore-eof has been used in a configuration file, this option restores the default for specific named daemons.

--running ✅ Check whether or not a named daemon is running, then exit(3) with EXIT_SUCCESS if running or EXIT_FAILURE if not. If --verbose is supplied, print a message. This option can only be used with --name.

--restart 🔄 Instruct a named daemon to terminate and restart its client process by sending it a SIGUSR1 signal. This causes the daemon to send SIGTERM to its client. If the named daemon had been started with --respawn, the client will be restarted. Otherwise, this has the same effect as --stop.

--stop 🛑 Stop a named daemon by sending it a SIGTERM signal. This causes the daemon to send SIGTERM to its client and then exit.

--signal=signame ðŸ“Ŋ Send the given signal to a named daemon's client process. The signal can be specified by number or name (with or without the "sig" prefix). Any signal may be sent, but the client might be ignoring some. Available signals: hup, int, quit, ill, trap, abrt, iot, bus, fpe, kill, usr1, segv, usr2, pipe, alrm, term, stkflt, cld, chld, cont, stop, tstp, ttin, ttou, urg, xcpu, xfsz, vtalrm, prof, winch, poll, io, pwr, sys, emt, info (not all on all platforms).

--list 📋 Print a list of the currently running named daemons whose pidfiles are in the applicable pidfile directory. Without --verbose, only lists names of daemons whose pidfiles are locked. With --verbose, shows more detail. If there are no pidfiles, output: "No named daemons are running".

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.

ðŸ”Ī EXPANSION

Some simple shell-like expansion is performed internally on the arguments of command line options with a text argument (but not numeric arguments). Environment variable notation ($VAR or ${VAR}) is expanded. Then user home directory notation (~ or ~user) is expanded. File name expansion (globbing) is NOT performed internally. This might not be of much use on the command line since daemon is normally invoked via a shell, but it can be useful in configuration files. By default, environment variable expansion is not performed for the root user. The --idiot option can change this.

📁 FILES

Each 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. They can include environment variable notation and user home directory notation. Configuration directives consist of a client name (or '*' for generic options), followed by spaces/tabs, followed by a comma-separated list of options. Option arguments must not contain commas. Blank lines and comments ('#' to end of line) are ignored. Lines can be continued with a '\' character at the end.

Command line options are processed first, then configuration files (generic '*' entries, then named entries), then command line options again. Note that --chroot, --user, and --name must not appear in configuration files.

📎 MESSAGING

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. Facilities: kern, user, mail, daemon, auth, syslog, lpr, news, uucp, cron, local0..local7. Priorities: emerg, alert, crit, err, warning, notice, info, debug. If a file path is supplied, use an absolute path because daemon changes to the root directory by default.

⚠ïļ CAVEAT

📚 SEE ALSO

libslack(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)

✍ïļ AUTHOR

20210304 raf <raf AT raf.org>


daemon-0.8 20210304 DAEMON(1)

DAEMON(7) daemon DAEMON(7)

📖 NAME

daemon - Writing and packaging system daemons

📝 DESCRIPTION

A daemon is a service process that runs in the background and supervises the system or provides functionality to other processes. Traditionally, daemons are implemented following a scheme originating in SysV Unix. Modern daemons should follow a simpler yet more powerful scheme (here called "new-style" daemons), as implemented by systemd(1). This manual page covers both schemes, and in particular includes recommendations for daemons that shall be included in the systemd init system.

🏛ïļ SysV Daemons

When a traditional SysV daemon starts, it should execute the following steps as part of the initialization. Note that these steps are unnecessary for new-style daemons (see below), and should only be implemented if compatibility with SysV is essential.

  1. Close all open file descriptors except standard input, output, and error (0, 1, 2). On Linux, iterate through /proc/self/fd, with fallback to iterating from fd 3 to the value returned by getrlimit() for RLIMIT_NOFILE.
  2. Reset all signal handlers to their default (SIG_DFL).
  3. Reset the signal mask using sigprocmask().
  4. Sanitize the environment block, removing or resetting environment variables that might negatively impact daemon runtime.
  5. Call fork() to create a background process.
  6. In the child, call setsid() to detach from any terminal and create an independent session.
  7. In the child, call fork() again to ensure the daemon can never re-acquire a terminal again.
  8. Call exit() in the first child, so that only the second child (the actual daemon process) stays around. This ensures the daemon is re-parented to init/PID 1.
  9. In the daemon process, connect /dev/null to standard input, output, and error.
  10. In the daemon process, reset the umask to 0.
  11. In the daemon process, change the current directory to the root directory (/).
  12. In the daemon process, write the daemon PID to a PID file (e.g., /run/foobar.pid) in a race-free fashion.
  13. In the daemon process, drop privileges, if possible and applicable.
  14. From the daemon process, notify the original process that initialization is complete via an unnamed pipe or similar communication channel.
  15. Call exit() in the original process. The invoking process must be able to rely on that this exit() happens after initialization is complete.

The BSD daemon() function should not be used, as it implements only a subset of these steps.

🆕 New-Style Daemons

Modern services for Linux should be implemented as new-style daemons. This makes it easier to supervise and control them at runtime and simplifies their implementation. For developing a new-style daemon, none of the initialization steps recommended for SysV daemons need to be implemented. New-style init systems such as systemd make all of them redundant.

It is recommended for new-style daemons to implement the following:

  1. If SIGTERM is received, shut down the daemon and exit cleanly.
  2. If SIGHUP is received, reload the configuration files, if applicable.
  3. Provide a correct exit code from the main daemon process, following the LSB recommendations for SysV init scripts.
  4. If possible and applicable, expose the daemon's control interface via D-Bus and grab a bus name as last step of initialization.
  5. For integration in systemd, provide a .service unit file.
  6. Rely on the init system's functionality to limit access to files, services, and resources.
  7. If D-Bus is used, make your daemon bus-activatable by supplying a D-Bus service activation configuration file.
  8. If your daemon provides services via sockets, make it socket-activatable.
  9. If applicable, notify the init system about startup completion via sd_notify(3).
  10. Instead of using syslog(), log to standard error via fprintf(), which is then forwarded to syslog by the init system. Log levels can be encoded by prefixing lines with strings like "<4>" (for WARNING).
  11. Always specify O_NOCTTY on open() calls that possibly reference a TTY device node.

These recommendations are similar but not identical to the Apple MacOS X Daemon Requirements.

🔌 ACTIVATION

New-style init systems provide multiple additional mechanisms to activate services. It is common for services to be configured to be activated via more than one mechanism at the same time.

ðŸ–Ĩïļ Activation on Boot

Old-style daemons are usually activated exclusively on boot via SysV init scripts. In systemd, to activate a service automatically on boot, place a symlink to the unit file in the .wants/ directory of either multi-user.target or graphical.target.

🔌 Socket-Based Activation

In socket-based activation, the creation and binding of the listening socket is moved out of the daemon code and into the init system. The init system installs the sockets and hands them off to the spawned process. This allows parallel start-up and on-demand activation. Daemons can be restarted without losing requests because the socket stays bound. New-style daemons must receive their sockets from the init system via sd_listen_fds(3) and daemon(3). systemd implements socket-based activation via .socket units. Place WantedBy=sockets.target in the [Install] section.

🚌 Bus-Based Activation

When D-Bus IPC is used, new-style daemons should employ bus activation so that they are automatically activated when a client accesses their IPC interfaces. Configure in D-Bus service files using SystemdService= directive to bind to the matching systemd service.

🔌 Device-Based Activation

Daemons managing hardware should be activated only when the hardware becomes available. In systemd, kernel devices tagged with "systemd" can be exposed as units. Use SYSTEMD_WANTS= property in udev database. It is often nicer to pull in services from devices indirectly via targets (e.g., bluetooth.target).

📁 Path-Based Activation

Activation can be bound to file system changes via .path units as outlined in systemd.path(5).

⏰ Timer-Based Activation

Jobs that are executed in regular intervals benefit from timer-based activation via .timer units as described in systemd.timer(5).

➕ Other Forms of Activation

Other forms of activation have been suggested but often have simpler alternatives. For example, use IP_FREEBIND for binding to non-local addresses, or leave scheduling to the OS scheduler with CPUSchedulingPolicy=idle and IOSchedulingClass=idle.

🔗 INTEGRATION WITH SYSTEMD

✍ïļ Writing systemd Unit Files

ðŸ“Ķ Installing systemd Service Files

At build installation time, install unit files in the directory returned by pkg-config systemd --variable=systemdsystemunitdir (for system services) or systemduserunitdir (for user services). During package installation, use systemctl enable to activate them automatically on boot.

For autoconf-based projects, use a configure script excerpt like the following to determine the unit installation path:

PKG_PROG_PKG_CONFIG
AC_ARG_WITH([systemdsystemunitdir],
     [AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],,
     [with_systemdsystemunitdir=auto])
AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [
     def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
     AS_IF([test "x$def_systemdsystemunitdir" = "x"],
   [AS_IF([test "x$with_systemdsystemunitdir" = "xyes"],
    [AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])])
    with_systemdsystemunitdir=no],
   [with_systemdsystemunitdir="$def_systemdsystemunitdir"])])
AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
      [AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])])
AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"])

Also add to top-level Makefile.am:

AM_DISTCHECK_CONFIGURE_FLAGS = \
  --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)

And install unit files with automake:

if HAVE_SYSTEMD
systemdsystemunit_DATA = \
  foobar.socket \
  foobar.service
endif

In RPM .spec files, use systemd macros:

BuildRequires: systemd
%{?systemd_requires}

%post
%systemd_post foobar.service foobar.socket

%preun
%systemd_preun foobar.service foobar.socket

%postun
%systemd_postun

For restart during upgrades, replace %postun with:

%postun
%systemd_postun_with_restart foobar.service

To facilitate upgrades from SysV to native systemd service, use a trigger:

%triggerun -- foobar < 0.47.11-1
if /sbin/chkconfig --level 5 foobar ; then
  /bin/systemctl --no-reload enable foobar.service foobar.socket >/dev/null 2>&1 || :
fi

🔄 PORTING EXISTING DAEMONS

To port an existing SysV daemon to new-style:

  1. Add an optional command line switch to disable daemonization.
  2. If the daemon offers local AF_UNIX sockets, implement socket-based activation: check sd_listen_fds(3) for already passed sockets; skip socket creation if passed; do not remove socket nodes; spare passed sockets from closing.
  3. Write and install a systemd unit file for the service (and sockets/path units if applicable).
  4. If the daemon exposes interfaces via D-Bus, write and install a D-Bus activation file.

📂 PLACING DAEMON DATA

It is recommended to follow the general guidelines for placing package files, as discussed in file-hierarchy(7).

📚 SEE ALSO

systemd(1), sd-daemon(3), sd_listen_fds(3), sd_notify(3), daemon(3), systemd.service(5), file-hierarchy(7)

📝 NOTES

  1. LSB recommendations for SysV init scripts: http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
  2. Apple MacOS X Daemon Requirements: https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html

systemd 249 DAEMON(7)

DAEMON(7)
📖 NAME 🚀 Quick Reference 🔖 SYNOPSIS 📝 DESCRIPTION ⚙ïļ OPTIONS ðŸ”Ī EXPANSION 📁 FILES 📎 MESSAGING ⚠ïļ CAVEAT 📚 SEE ALSO ✍ïļ AUTHOR 📖 NAME 📝 DESCRIPTION
🏛ïļ SysV Daemons 🆕 New-Style Daemons
🔌 ACTIVATION
ðŸ–Ĩïļ Activation on Boot 🔌 Socket-Based Activation 🚌 Bus-Based Activation 🔌 Device-Based Activation 📁 Path-Based Activation ⏰ Timer-Based Activation ➕ Other Forms of Activation
🔗 INTEGRATION WITH SYSTEMD
✍ïļ Writing systemd Unit Files ðŸ“Ķ Installing systemd Service Files
🔄 PORTING EXISTING DAEMONS 📂 PLACING DAEMON DATA 📚 SEE ALSO 📝 NOTES

Generated by phpman v4.9.26-5-g7740029 Author: Che Dong Under GNU General Public License
2026-08-24 03:46 @216.73.216.102
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!