Definition
What it is
A daemon has no terminal. It does not read from stdin, does not write to stdout unless redirected, and does not die when the user logs out. It starts at boot (via init, systemd, launchd, or Windows Service Control Manager), runs for hours, days or years, and is restarted if it crashes. Common daemons: sshd (SSH server), cron (scheduler), nginx (web server), mysqld (MySQL), systemd-journald (log collector), dockerd (Docker).
The daemonizing process is a sequence: fork, setsid, fork again (to prevent reacquiring a terminal), chdir to root (or a fixed dir), reset umask, close inherited file descriptors, redirect 0/1/2 to /dev/null. Modern systems use systemd's Type=simple or Type=forking to manage this without the process daemonizing itself.
Why it matters
The whole architecture of Unix networking depends on daemons. When you visit example.com, the server running nginx is a daemon, started at boot, independent of any user. When you SSH into a box, sshd listens on port 22 as a daemon. When you cron a job, crond runs it as a daemon. Without daemons, every service would require a human logged in with a terminal open — the opposite of a server.
Daemon vs service vs cron vs process
Aspect | Daemon | Service | Cron | Process |
|---|---|---|---|---|
Runs continuously | Yes | Yes | No (periodic) | Any duration |
Detached from TTY | Yes | Yes | N/A | No |
Managed by | init/systemd | systemd/launchd | Kernel | |
Typical example | sshd, nginx | same ones | crond jobs | Any program |
Starts at boot | Yes | Yes | Yes | No |
The daemon lifecycle
graph LR
B[Boot] --> S[systemd]
S --> D[Daemon process]
D --> R[Run, serve]
R --> C{Crash?}
C -->|Yes| S
C -->|No| R
style D fill:#E8F5E9
style S fill:#FFF3E0
Writing a daemon
Modern daemon rules
Prefer systemd
Type=simplelets systemd manage the process. No daemonizing code needed. The process just runs in the foreground.Fork twice if you must daemonize
fork→ parent exits →setsid→forkagain → grandparent exits. Child has no TTY, is a session leader.Chdir to /
A daemon should not keep the cwd pinned to a filesystem; that prevents unmounting.
Reset umask
umask(0)so the daemon's file creation is not inherited from the shell.Redirect stdio
freopen('/dev/null', 'r', stdin); freopen('/dev/null', 'w', stdout); freopen('/dev/null', 'w', stderr);Log to syslog or journald
Not to stdout. Logs need to survive the daemon's restart.
Common failures
Origin
In 1867, physicist James Clerk Maxwell imagined a "demon" that could sort molecules by speed, violating the second law of thermodynamics (it cannot, if you account for its own entropy). In 1963, MIT's Project MAC (Multics precursor) adopted "daemon" for background processes that sort and dispatch tasks — the metaphor was Maxwell's sorting demon. The term survived into Unix (1969), where daemons were the standard name for long-running background processes. The Devil-in-the-machine connotation is intentional but benign: the daemon is a helpful spirit, not a malevolent one.
Daemons are processes that are not associated with a terminal and are usually started at boot time. The name comes from Maxwell's demon, a thought experiment in physics.
— Unix System Administration Handbook (Nemeth et al.), 4th ed., 2010
Evidence
FAQ
- How do I identify a daemon?
Process has no controlling TTY (check with
ps -o tty), often ends ind(sshd, crond, httpd), started by init.- Why the "d" suffix?
Convention from Unix:
sshdis the daemon for ssh;httpdis the daemon for http.mysqldis the MySQL daemon.- Did systemd kill daemons?
No. It changed how they are managed: the process runs in the foreground, systemd handles the daemonizing. The concept is the same; the code is simpler.
- Daemon vs container?
A container runs one foreground process. The orchestrator (Kubernetes) acts as the daemon manager. Same idea, different vocabulary.
Connections
FreeBSD (2024). daemon(8). https://man.freebsd.org/cgi/man.cgi?query=daemon&sektion=8
Nemeth, E. et al. (2010). Unix and Linux System Administration Handbook, 4th ed. https://www.admin.com/
systemd (2024). systemd.service(5). https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html
Etymology
Origin: metaphor
daemon(noun): from Greek daimon, "spirit, divine power"; via Maxwell's demon (1867) and Project MAC (1963)
Semantic network
● broader ● narrower ● related
Used in the garden
Sources
FreeBSD (2024). daemon(8). https://man.freebsd.org/cgi/man.cgi?query=daemon&sektion=8
Nemeth, E. et al. (2010). Unix and Linux System Administration Handbook, 4th ed. https://www.admin.com/
systemd (2024). systemd.service(5). https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html