# man > daemon(1)

---
type: CommandReference
command: daemon
mode: man
section: "1"
source: man-pages
---

## Quick Reference

- `daemon -n "name" command` — Run a command as a daemon.
- `daemon -n "name" -r command` — Run a command as a daemon which will restart if the command crashes.
- `daemon -n "name" -r -A 2 -L 10 command` — Run with restart, two attempts every 10 seconds.
- `daemon -n "name" -l path/to/file.log command` — Run as daemon, writing logs to a specific file.
- `daemon -n "name" --stop` — Kill a daemon (SIGTERM).
- `daemon --list` — List daemons.

## Name

daemon - turns other processes into daemons

## Synopsis

usage: daemon [options] [--] [cmd arg...]
## Options

### General Options

- `-h, --help` — Print a help message and exit.
- `-V, --version` — Print a version message and exit.
- `-v [level], --verbose[=level]` — Set verbosity level (default 1). Affects `--running` and `--list`.
- `-d [level], --debug[=level]` — Set debug level (default 1). Levels 1–9. Debug messages sent to `--dbglog` destination.

### Configuration

- `-C path, --config=path` — Specify system configuration file. Default: `/etc/daemon.conf` (or `/usr/local/etc/daemon.conf` on BSD, `/opt/local/etc/daemon.conf` on macOS via MacPorts).
- `-N, --noconfig` — Bypass system configuration files.
- `-U, --unsafe` — Allow reading unsafe configuration/executable (root only, dangerous).
- `-S, --safe` — Disallow unsafe configuration/executable (default for root).
- `-c, --core` — Allow core file generation (for debugging, can leak sensitive info).
- `--nocore` — Disallow core file generation (default).
- `-i, --inherit` — Explicitly inherit environment variables when using `--env`.
- `-e "var=val", --env="var=val"` — Set an environment variable for the client. Can be used multiple times.
- `-m umask, --umask=umask` — Set umask (default 022). Must be a valid octal mode.
- `-D path, --chdir=path` — Change current directory before running client.
- `-R path, --chroot=path` — Change root directory before running client. Only root on some systems.
- `-u user[:group], --user=user[:group]` — Run client as a different user (and group). Only root.
- `-X "cmd", --command="cmd"` — Specify client command as an option. Additional command-line arguments are appended.
- `-n name, --name=name` — Ensure single named instance; create and lock a pidfile (`name.pid`). Default location: `/var/run` (root), `/tmp` (normal users).
- `-P /dir, --pidfiles=/dir` — Override pidfile directory.
- `-F /path, --pidfile=/path` — Override pidfile name and location.

### Respawn

- `-r, --respawn` — Respawn the client when it terminates.
- `-a #, --acceptable=#` — Minimum acceptable client duration in seconds (default 300, min 10). Requires `--respawn`.
- `-A #, --attempts=#` — Number of respawn attempts before delay (default 5, max 100). Requires `--respawn`.
- `-L #, --delay=#` — Delay between respawn attempt bursts in seconds (default 300, min 10). Requires `--respawn`.
- `-M #, --limit=#` — Maximum number of respawn attempt bursts (default 0 = no limit). Requires `--respawn`.
- `--idiot` — Disable minimum/maximum limits on `-a`, `-A`, `-L`; allow environment variable expansion for root. Only root. **Use with extreme caution.**

### Foreground / PTY

- `-f, --foreground` — Run the client in the foreground (not a daemon).
- `-p [noecho], --pty[=noecho]` — Allocate a pseudo terminal for the client. Requires `--foreground`. Use `noecho` if input is echoed twice. **Note:** Job control (Ctrl+Z) does not work with pseudo terminal because the client belongs to an orphaned process group.

### Bind

- `-B, --bind` — Automatically terminate the client when the user has no systemd-logind or elogind sessions (i.e., logs out). Linux only.

### Logging and Output

- `-l spec, --errlog=spec` — Send daemon's error output to syslog (`facility.priority`) or file. Default: `daemon.err`.
- `-b spec, --dbglog=spec` — Send daemon's debug output to syslog or file. Default: `daemon.debug`.
- `-o spec, --output=spec` — Capture client's stdout and stderr to syslog or file.
- `-O spec, --stdout=spec` — Capture client's stdout to syslog or file.
- `-E spec, --stderr=spec` — Capture client's stderr to syslog or file.
- `--ignore-eof` — After SIGCHLD, reap client immediately without reading output (avoids waiting for child processes).
- `--read-eof` — After SIGCHLD, read client output until EOF before reaping (default).

### Control (Named Daemons)

- `--running` — Check if a named daemon is running. Exit status 0 if running, 1 if not. Requires `--name`.
- `--restart` — Instruct a named daemon to restart its client (sends SIGUSR1). **Note:** Client must have been started with `--respawn`; otherwise it behaves like `--stop`. Requires `--name`.
- `--stop` — Stop a named daemon (sends SIGTERM). Requires `--name`.
- `--signal=signame` — Send a signal to a named daemon's client process. Signal can be number or name (with or without "sig" prefix). Requires `--name`.
- `--list` — Print a list of currently running named daemons.

## Examples

shell
# Run a command as a daemon
daemon -n "name" command

# Run a command as a daemon which will restart if the command crashes
daemon -n "name" -r command

# Run a command as a daemon which will restart if it crashes, with two attempts every 10 seconds
daemon -n "name" -r -A 2 -L 10 command

# Run a command as a daemon, writing logs to a specific file
daemon -n "name" -l path/to/file.log command

# Kill a daemon (SIGTERM)
daemon -n "name" --stop

# List daemons
daemon --list
Configuration file example (`/etc/daemon.conf`):

text
*       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
## See Also

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