# DAEMON - turns other processes into daemons - man - [phpMan]

> **TLDR:** Turns other processes into daemons.
>
- Run a command as a daemon:
  `daemon {{-n|--name}} "{{name}}" {{command}}`
- Run a command as a daemon which will restart if the command crashes:
  `daemon {{-n|--name}} "{{name}}" {{-r|--respawn}} {{command}}`
- Run a command as a daemon which will restart if it crashes, with two attempts every 10 seconds:
  `daemon {{-n|--name}} "{{name}}" {{-r|--respawn}} {{-A|--attempts}} 2 {{-L|--delay}} 10 {{command}}`
- Run a command as a daemon, writing logs to a specific file:
  `daemon {{-n|--name}} "{{name}}" {{-l|--errlog}} {{path/to/file.log}} {{command}}`
- Kill a daemon (SIGTERM):
  `daemon {{-n|--name}} "{{name}}" --stop`
- List daemons:
  `daemon --list`

*Source: tldr-pages*

---

[_DAEMON_(1)](https://www.chedong.com/phpMan.php/man/DAEMON/1/markdown)                                   User Commands                                  [_DAEMON_(1)](https://www.chedong.com/phpMan.php/man/DAEMON/1/markdown)

## NAME
       daemon - turns other processes into daemons

## 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)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_ 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:

       •   First,  revoke  any  setuid or setgid privileges that _daemon_ may have been installed with
           (by system administrators who laugh in the face of danger).

       •   Process command line options.

       •   Change the root directory if the --chroot option was supplied.

       •   Change the process uid and gid if the --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.

       •   Read the system  configuration  file(s)  (/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.**

           On   _BSD_   systems   (except   _macOS_),   the    system    configuration    file(s)    are
           /usr/local/etc/daemon.conf and /usr/local/etc/daemon.conf.d/* by default.

           On   _macOS_,   when   installed   via  _macports_,  the  system  configuration  file(s)  are
           /opt/local/etc/daemon.conf and /opt/local/etc/daemon.conf.d/*.

       •   Disable core file generation to prevent  leaking  potentially  sensitive  information  in
           daemons that are run by _root_ (unless the --core option was supplied).

       •   Become a daemon process:

           •   If  _daemon_  was  not  invoked by _**[init**(8)](https://www.chedong.com/phpMan.php/man/init/8/markdown)_ (i.e. parent process id 1) or _**[inetd**(8)](https://www.chedong.com/phpMan.php/man/inetd/8/markdown)_ (i.e.
               stdin is a socket):

               •   Ignore SIGHUP signals in case the current process session leader terminates while
                   attached to a controlling terminal, causing us to receive a SIGHUP signal  before
                   we start our own process session below.

                   This can happen when _daemon_ was invoked interactively via the shell builtin exec.
                   When  this  initial  process terminates below, the terminal emulator that invoked
                   the shell also terminates, so _daemon_ need to protect itself from that.

               •   Background the process to lose process group leadership.

               •   Start a new process session.

               •   Background the process again to lose process session leadership. Under _SVR4_, this
                   prevents the process from ever gaining a  controlling  terminal.   This  is  only
                   necessary  under  _SVR4_,  but  is  always done for simplicity.  Note that ignoring
                   SIGHUP signals earlier means that when the newly created process  session  leader
                   terminates,  then  even  if  it  has  a  controlling  terminal  open,  the  newly
                   backgrounded process won't receive the corresponding SIGHUP signal that  is  sent
                   to  all  processes  in the process session's foreground process group, because it
                   inherited signal dispositions from the initial process.

           •   Change the current directory to the root directory so as not to hamper umounts.

           •   Clear the _umask_ to enable explicit file creation modes.

           •   Close all open file descriptors. If _daemon_ was invoked by _**[inetd**(8)](https://www.chedong.com/phpMan.php/man/inetd/8/markdown)_, stdin, stdout and
               stderr are left open, because they are open to a socket.

           •   Open stdin, stdout and stderr to /dev/null, in case something  requires  them  to  be
               open. Of course, this is not done if _daemon_ was invoked by _**[inetd**(8)](https://www.chedong.com/phpMan.php/man/inetd/8/markdown)_.

           •   If  the  --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.

       •   If the --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.

       •   Set the current directory if the --chdir option was supplied.

       •   Spawn the client command and wait  for  it  to  terminate.  The  client  command  can  be
           specified  as command line arguments, or as the argument of the --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.

       •   If  the  --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.

       •   When  the  client terminates, _daemon_ respawns it if the --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.

           When  the  client terminates, and the --respawn option wasn't supplied, _daemon_ terminates
           as well.

       •   If _daemon_ receives a SIGTERM signal (e.g. from a separate invocation of _daemon_  with  the
           --stop option), it propagates the signal to the client and then terminates.

       •   If  _daemon_  receives  a  SIGUSR1  signal  (from  a separate invocation of _daemon_ with the
           --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.

       •   If the --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.

## 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 _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)](https://www.chedong.com/phpMan.php/man/select/2/markdown)_.  Debug  messages  are  sent  to  the destination specified by the
           --dbglog option (by default, the _**[syslog**(3)](https://www.chedong.com/phpMan.php/man/syslog/3/markdown)_ 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.

           As  well  as  the  system configuration file, additional configuration files will be read
           from the directory whose path matches the system configuration file with ".d" appended to
           it (e.g. /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.

           On   _BSD_   systems   (except   _macOS_),   the    system    configuration    file(s)    are
           /usr/local/etc/daemon.conf and /usr/local/etc/daemon.conf.d/* by default.

           On   _macOS_,   when   installed   via  _macports_,  the  system  configuration  file(s)  are
           /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.

           The name may only consist of the following characters:

               -._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

           While  a  named daemon's client process is running, there will also be a separate pidfile
           to record the process id of the client process. Its filename will  be  the  same  as  the
           _daemon_ pidfile's, except that the filename extension will be .clientpid rather than .pid.
           The  only reason that there should be a .pid file, with no .clientpid file, is during the
           delay between respawn attempts bursts.

       -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

           **Note: **If the client command is  specified  with  the  --command  option,  either  in  the
           configuration file, or on the command line, then any additional command line arguments on
           the  _daemon_  command  line  are appended to the client command that is specified with the
           --command option.

       -P _/dir_, --pidfiles=_/dir_
           Override the standard pidfile location. The standard pidfile  location  is  /var/run  for
           root (/etc on _Solaris_, /opt/local/var/run on _macOS_ when installed via _macports_), and /tmp
           for normal users.

           This option only affects the --name and --list options. Use this option if these standard
           locations  are  unacceptable,  but  make  sure  that  you don't forget where you put your
           pidfiles. This option is best used in configuration files, or in  shell  scripts,  rather
           than on an interactive command line.

           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  standard  pidfile  location  is
           described  immediately  above.  The  standard  pidfile name is the argument of the --name
           option followed by .pid. Use this option if the standard pidfile name  and  location  are
           unacceptable, but make sure that you don't forget where you put your pidfile. This option
           is  best  used in configuration files, or in shell scripts, rather than on an interactive
           command line.

           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). 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. For
           backwards compatibility, "." may be used instead of ":" to separate the  user  and  group
           but  since  "."  can  appear in user and group names, ambiguities can arise such as using
           --user=_u.g_ when users _u_ and _u.g_ and group _g_ all exist. With  such  an  ambiguity,  _daemon_
           will assume the user _u_ and group _g_. Use --user=_u.g:_ instead for the other interpretation.

       -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). If an executable is a script that is interpreted by another  executable,
           then  it  is  considered to be unsafe if the interpreter is unsafe. If the interpreter is
           /usr/bin/env (with an argument that is a command name to be searched for in $PATH),  then
           that  command  must  be  safe.  By  default,  _**[daemon**(1)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_  will  refuse  to  read an unsafe
           configuration file or to execute an unsafe executable  when  run  by  _root_.  This  option
           overrides that behaviour and hence should never be used.

### -S, --safe
           Disallow  reading  an  unsafe configuration file, and disallow the execution of an unsafe
           executable. By default, _**[daemon**(1)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_ will allow reading an unsafe  configuration  file,  and
           allow  the  execution  of  an  unsafe  executable,  when run by normal users. This option
           overrides that behaviour.

### -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, because
           it can turn a slight misconfiguration into a lot of wasted CPU energy and  log  messages,
           somewhat akin to a self-inflicted denial of service.

           Idiot  mode  also allows the _root_ user to expand environment variable notation (e.g. $VAR
           and ${VAR}) in command line option arguments, and in  configuration  files.  By  default,
           internal  environment  variable  expansion  is only performed for normal users. Note that
           this doesn't apply to any such expansion performed earlier  by  the  shell  that  invokes
           _**[daemon**(1)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_. See the EXPANSION section below for more details.

### -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. This option is only necessary when
           the client process must be connected to a controlling terminal,  but  _daemon_  itself  has
           been run without a controlling terminal (e.g. from _**[cron**(8)](https://www.chedong.com/phpMan.php/man/cron/8/markdown)_ or a pipeline).

           If  the  noecho  argument  is  supplied with this option, the client's side of the pseudo
           terminal will be set to noecho mode. Use this only if there really is a terminal involved
           and input is being echoed twice.

### -B, --bind
           Automatically terminate the client process (and _**[daemon**(1)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_ itself) as soon as the user has
           no _**[systemd-logind**(8)](https://www.chedong.com/phpMan.php/man/systemd-logind/8/markdown)_  (or  _**[elogind**(8)](https://www.chedong.com/phpMan.php/man/elogind/8/markdown)_)  user  sessions.  In  other  words,  automatically
           terminate  when  the user logs out. If the user has no sessions to start with, the client
           process will be terminated immediately.

           This option is only available on _Linux_ systems that have either _**[systemd**(1)](https://www.chedong.com/phpMan.php/man/systemd/1/markdown)_ (e.g.  _Debian_)
           or  _**[elogind**(8)](https://www.chedong.com/phpMan.php/man/elogind/8/markdown)_  (e.g.  _Slackware_).  On  systems  with _**[systemd**(1)](https://www.chedong.com/phpMan.php/man/systemd/1/markdown)_, you could instead use a
           _systemd_ user service, particularly if your user account  is  not  allowed  to  have  user
           services that _linger_.

       -l _spec_, --errlog=_spec_
           Send  _daemon_'s  standard output and standard error to the syslog destination or file that
           is specified by _spec_. If _spec_ is a syslog destination of  the  form  "facility.priority",
           then output is sent to _**[syslog**(3)](https://www.chedong.com/phpMan.php/man/syslog/3/markdown)_. Otherwise, output is appended to the file whose path is
           given  in _spec_. By default, output is sent to the syslog destination, daemon.err. See the
           MESSAGING section below for more details.

       -b _spec_, --dbglog=_spec_
           Send _daemon_'s debug output to the syslog destination or file that is specified  by  _spec_.
           If  _spec_  is a syslog destination of the form "facility.priority", then output is sent to
           _**[syslog**(3)](https://www.chedong.com/phpMan.php/man/syslog/3/markdown)_. Otherwise, output is appended to the file whose path  is  given  in  _spec_.  By
           default, output is sent to the syslog destination daemon.debug. See the MESSAGING section
           below for more details.

       -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_. If _spec_ is a  syslog  destination  of  the
           form "facility.priority", then output is sent to _**[syslog**(3)](https://www.chedong.com/phpMan.php/man/syslog/3/markdown)_. Otherwise, output is appended
           to  the  file  whose  path  is  given in _spec_. By default, output is discarded unless the
           --foreground option is present, in  which  case,  the  client's  stdout  and  stderr  are
           propagated  to  _daemon_'s stdout and stderr, respectively. See the MESSAGING section below
           for more details.

       -O _spec_, --stdout=_spec_
           Capture the client's standard output, and send it to the syslog destination or file  that
           is  specified  by  _spec_. If _spec_ is a syslog destination of the form "facility.priority",
           then output is sent to _**[syslog**(3)](https://www.chedong.com/phpMan.php/man/syslog/3/markdown)_.  Otherwise, stdout is appended to the file  whose  path
           is  given  in  _spec_.  By  default,  stdout is discarded unless the --foreground option is
           present, in which case, the client's stdout is propagated to  _daemon_'s  stdout.  See  the
           MESSAGING section below for more details.

       -E _spec_, --stderr=_spec_
           Capture  the  client's standard error, and send it to the syslog destination or file that
           is specified by _spec_. If _spec_ is a syslog destination of  the  form  "facility.priority",
           then  stderr  is sent to _**[syslog**(3)](https://www.chedong.com/phpMan.php/man/syslog/3/markdown)_.  Otherwise, stderr is appended to the file whose path
           is given in _spec_. By default, stderr is  discarded  unless  the  --foreground  option  is
           present,  in  which  case,  the client's stderr is propagated to _daemon_'s stderr. See the
           MESSAGING section below for more details.

### --ignore-eof
           After receiving a SIGCHLD signal due to a stopped  or  restarted  client  process,  don't
           bother  reading  the  client's output until the end-of-file is reached before reaping the
           client process's termination status with _**[wait**(2)](https://www.chedong.com/phpMan.php/man/wait/2/markdown)_. Normally, there will be  little  or  no
           output after the SIGCHLD signal, because the client process has just terminated. However,
           the  client process might have its own child processes keeping its output open long after
           its own termination. When this happens, by default,  the  client  process  remains  as  a
           zombie  process until its child processes terminate and close the output. Waiting for the
           client's child processes to terminate before considering the client stopped,  and  before
           restarting  a  new  invocation,  might  be  desirable. If not, this option can be used to
           consider the client process as being terminated as soon as the SIGCHLD  signal  has  been
           received, and reaping its termination status with _**[wait**(2)](https://www.chedong.com/phpMan.php/man/wait/2/markdown)_ immediately.

### --read-eof
           After  receiving  a SIGCHLD signal due to a stopped or restarted client process, continue
           reading the client's output until the end-of-file is reached before  reaping  the  client
           process's termination status with _**[wait**(2)](https://www.chedong.com/phpMan.php/man/wait/2/markdown)_. This is the default behaviour. Normally, there
           will be little or no output after the SIGCHLD signal, because the client process has just
           terminated.  However,  the  client process might have its own child processes keeping its
           output open long after its own termination. When this happens, the client process remains
           as a zombie process until its child processes terminate and close the output. Waiting for
           the client's child processes to terminate before  considering  the  client  stopped,  and
           before  restarting  a  new  invocation,  might  be desirable. If so, but the --ignore-eof
           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.

### --running
           Check  whether  or  not  a named daemon is running, then _**[exit**(3)](https://www.chedong.com/phpMan.php/man/exit/3/markdown)_ with EXIT_SUCCESS if the
           named daemon is running or EXIT_FAILURE if it isn't.

           If the --verbose option is supplied, print a message before exiting. If  both  the  named
           daemon  and  its client process are running, the output will look like this, showing both
           process IDs:

               daemon:  name is running (pid 7455) (clientpid 7457)

           If the named daemon is running but its client process is not  (there  might  be  a  delay
           between  respawn attempt bursts), the output will look like this, showing only the daemon
           process's ID:

               daemon:  name is running (pid 7455) (client is not running)

           If the named daemon is not running at all, the output will look like this:

               daemon:  name is not running

           This option can only be used with the --name option.  Note  that  the  --chroot,  --user,
           --name,  --pidfiles and --pidfile (and possibly --config) options must be the same as for
           the target daemon.

### --restart
           Instruct a named daemon to terminate and restart its client  process,  by  sending  it  a
           SIGUSR1  signal.  This  will  cause the named daemon to send its client process a SIGTERM
           signal to stop it. If the named daemon had been started with the  --restart  option,  the
           named daemon will then restart its client process. Otherwise, this has the same effect as
           the --stop option, and the named daemon's client process is not restarted.

           This  option  can  only  be  used with the --name option. Note that the --chroot, --user,
           --name, --pidfiles and --pidfile (and possibly --config) options must be the same as  for
           the target daemon.

### --stop
           Stop  a  named daemon by sending it a SIGTERM signal. This will cause the named daemon to
           send its client process a SIGTERM option and then exit.

           This option can only be used with the --name option.  Note  that  the  --chroot,  --user,
           --name,  --pidfiles and --pidfile (and possibly --config) options must be the same as for
           the target daemon.

       --signal=_signame_
           Send the given signal to a named daemon's client process. The  signal  can  be  specified
           either  by number or by name (with or without the "sig" prefix).  Any signal may be sent.
           However, the named daemon's client process might be ignoring some signals.  For  example,
           SIGHUP  will  be  ignored  by  default  unless  the client process has installed a signal
           handler for it.

           The known list of signals are: 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 and info. Not all of them are
           available on all platforms.

### --list
           Print a list of the currently running named daemons whose pidfiles are in the  applicable
           pidfile  directory  which  will  either  be the default (i.e.  /var/run for _root_ (/etc on
           _Solaris_, /opt/local/var/run on _macOS_ when installed via _macports_), and  /tmp  for  normal
           users), or it will be specified by the --pidfiles option. Then exit.

           Without the --verbose option, this will only list the names of daemons whose pidfiles are
           locked,  as  this  implies that the corresponding daemon must still be running. Note that
           pidfiles for daemons that were not started by _**[daemon**(1)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_ might not be locked. An  unlocked
           pidfile  might  indicate  that  _**[daemon**(1)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_  has  died  unexpectedly, or it might just be a
           pidfile for a daemon that was not started by _**[daemon**(1)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_. If this might lead to  confusion,
           you might want to consider using a dedicated pidfiles directory for named daemons started
           by  _**[daemon**(1)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_,  and  leave  the  default pidfiles directories for other daemons that were
           started independently of _**[daemon**(1)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_.

           With the --verbose option, the items in the  list  will  look  like  the  output  of  the
           --running option with --verbose, but with more detail.

           If there are no pidfiles at all, the output will look like this:

               No named daemons are running

           If  a pidfile is locked, and there is a corresponding client pidfile, that indicates that
           the named daemon and its client are both running, and the output  will  look  like  this,
           showing both process IDs:

               name is running (pid ####) (client pid ####)

           If  a  pidfile  is  locked, but there is no client pidfile, that indicates that the named
           daemon is running, but its client is not (e.g. during a  delay  between  respawn  attempt
           bursts  when  the client is failing to start successfully), and the output will look like
           one of the following three options:

           When we can tell that the pidfile is for a process whose executable name is _daemon_:

               name is running (pid ####) (client is not running)

           When we can tell that the pidfile is for a process whose  executable  name  is  something
           other than _daemon_ (i.e. is independent of _**[daemon**(1)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_):

               name is running (pid ####) (independent)

           When  it's  not  possible  to  determine  the  name of the executable associated with the
           _pidfile_ (i.e. On systems other than _Linux_ without a /proc file system):

               name is running (pid ####) (client is not running or is independent)

           If a pidfile is not locked, and the applicable pidfiles directory is  the  default,  that
           indicates either that the daemon has unexpectedly terminated, or just that the pidfile is
           for a daemon that was not started by _**[daemon**(1)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_, and the output will look like this:

               name is not running (or is independent)

           If  a  pidfile  is  not locked, and the applicable pidfiles directory is not the default,
           then it is assumed that all pidfiles are for daemons that were started by _**[daemon**(1)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_,  and
           the output will look like this:

               name is not 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 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.

## FILES
       /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 options

       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  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.

## 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. Here
       are the lists of syslog facilities and priorities:

         Facilities:
         kern, user, mail, daemon, auth, syslog, lpr, news, uucp, cron,
         local0, local1, local2, local3, local4, local5, local6, local7.

         Priorities:
         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)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_  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)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_ 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.

## CAVEAT
       Clients can only be restarted if they were started with the --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.

       Clients that are run in the foreground with a pseudo terminal don't respond  to  job  control
       (i.e.  suspending  with  Control-Z  doesn't  work).  This is because the client belongs to an
       orphaned process group (it starts in its own process session), so the kernel  won't  send  it
       SIGSTOP  signals.   However,  if  the  client  is a shell that supports job control, then its
       subprocesses can be suspended.

       In KDE, if you use "exec daemon" (or just "exec" without daemon) in a shell,  to  run  a  KDE
       application,  you might find that the KDE application sometimes doesn't run. This problem has
       only been seen with _**[konsole**(1)](https://www.chedong.com/phpMan.php/man/konsole/1/markdown)_, but it might happen with  other  KDE  applications  as  well.
       Capturing the standard error of the KDE application might show something like:

         unnamed [app(9697)](https://www.chedong.com/phpMan.php/man/app/9697/markdown): KUniqueApplication: Registering failed!
         unnamed [app(9697)](https://www.chedong.com/phpMan.php/man/app/9697/markdown): Communication problem with  "konsole" , it probably crashed.
         Error message was:  "org.freedesktop.DBus.Error.ServiceUnknown" : " "The name
                             org.kde.konsole was not provided by any .service files"

       A  workaround  seems  to  be  to delay the termination of the initial _**[daemon**(1)](https://www.chedong.com/phpMan.php/man/daemon/1/markdown)_ process by at
       least   0.4   seconds.   To   make   this    happen,    set    the    environment    variable
       DAEMON_INIT_EXIT_DELAY_MSEC  to  the  number  of milliseconds by which to delay. For example:
       DAEMON_INIT_EXIT_DELAY_MSEC=400. Or you  could  just  avoid  using  exec  when  starting  _KDE_
       applications.

       On  _Linux_  systems  that  have  _**[systemd**(1)](https://www.chedong.com/phpMan.php/man/systemd/1/markdown)_  or  _**[elogind**(8)](https://www.chedong.com/phpMan.php/man/elogind/8/markdown)_,  you  might find that your _daemon_
       processes and their client processes are terminated when you logout, even though they are  in
       a  different  process  session,  and so should be unaffected. This is because _systemd_ has the
       ability to terminate all of your processes when you logout. Luckily, this feature  is  turned
       off  by  default  in  some  _Linux_ distributions. However, if it is on, you can turn it off by
       adding the following line to /etc/systemd/logind.conf (or /etc/elogind/logind.conf):

         KillUserProcesses=no

## SEE ALSO
       _**[libslack**(3)](https://www.chedong.com/phpMan.php/man/libslack/3/markdown)_,  _**[daemon**(3)](https://www.chedong.com/phpMan.php/man/daemon/3/markdown)_,  _**[coproc**(3)](https://www.chedong.com/phpMan.php/man/coproc/3/markdown)_,  _**[pseudo**(3)](https://www.chedong.com/phpMan.php/man/pseudo/3/markdown)_,  _**[init**(8)](https://www.chedong.com/phpMan.php/man/init/8/markdown)_,   _**[inetd**(8)](https://www.chedong.com/phpMan.php/man/inetd/8/markdown)_,   _**[fork**(2)](https://www.chedong.com/phpMan.php/man/fork/2/markdown)_,   _**[umask**(2)](https://www.chedong.com/phpMan.php/man/umask/2/markdown)_,
       _**[setsid**(2)](https://www.chedong.com/phpMan.php/man/setsid/2/markdown)_,   _**[chdir**(2)](https://www.chedong.com/phpMan.php/man/chdir/2/markdown)_,   _**[chroot**(2)](https://www.chedong.com/phpMan.php/man/chroot/2/markdown)_,   _**[setrlimit**(2)](https://www.chedong.com/phpMan.php/man/setrlimit/2/markdown)_,   _**[setgid**(2)](https://www.chedong.com/phpMan.php/man/setgid/2/markdown)_,   _**[setuid**(2)](https://www.chedong.com/phpMan.php/man/setuid/2/markdown)_,   _**[setgroups**(2)](https://www.chedong.com/phpMan.php/man/setgroups/2/markdown)_,
       _**[initgroups**(3)](https://www.chedong.com/phpMan.php/man/initgroups/3/markdown)_, _**[syslog**(3)](https://www.chedong.com/phpMan.php/man/syslog/3/markdown)_, _**[kill**(2)](https://www.chedong.com/phpMan.php/man/kill/2/markdown)_, _**[wait**(2)](https://www.chedong.com/phpMan.php/man/wait/2/markdown)_, _**[systemd-logind**(8)](https://www.chedong.com/phpMan.php/man/systemd-logind/8/markdown)_, _**[elogind**(8)](https://www.chedong.com/phpMan.php/man/elogind/8/markdown)_

## AUTHOR
       20230824 raf <<raf@raf.org>>

daemon-0.8.4                                  20230824                                     [_DAEMON_(1)](https://www.chedong.com/phpMan.php/man/DAEMON/1/markdown)
