Daemon
- Pronunciation
- DEE-mun
In short
A daemon is a program that runs in the background without a user interface, usually started at boot, to provide a service such as logging, scheduling, or SSH.
What is a daemon in computing?
A daemon is a long-running background process that is not attached to any terminal or user session. It usually starts when the system boots and quietly waits for work: incoming network connections, scheduled times, file changes, or requests from other programs. On Unix-like systems daemon names traditionally end in d, as in sshd, crond, and systemd.
Traditionally, a program turned itself into a daemon by forking, detaching from its terminal, changing its working directory to /, and redirecting its input and output away from the screen. Today a service manager, such as systemd on most Linux distributions or launchd on macOS, starts daemons at boot, restarts them if they crash, and collects their logs, so the program can simply run in the foreground. Daemons are commonly controlled with Unix signals, for example SIGHUP to reload configuration. On Windows, the same idea is called a service.
A daemon is like a building's night security guard: always on duty in the background, rarely seen, and ready the moment someone needs something. Web servers, database servers, the SSH server, print spoolers, the cron scheduler, and container runtimes all run as daemons.
A daemon is different from a job you start in the shell with &. A background shell job is still tied to your terminal session and may be stopped when you log out, while a daemon is detached and managed by the system. It is also different from a background job in an application, which is a unit of work such as sending an email; the worker process that runs those jobs is often itself a daemon. A daemon thread in Java or Python is another unrelated idea: a thread that doesn't keep the program alive when the main thread exits.
Key takeaways
- A daemon is a background process with no terminal or user interface.
- Daemons usually start at boot and wait for requests or events.
- Service managers such as systemd start, stop, and restart daemons.
- Many daemon names end in d, such as
sshdandcrond. - On Windows, the equivalent is called a service.
Example
# List running services (daemons) managed by systemd
systemctl list-units --type=service --state=running
# Check, restart, and enable the SSH daemon at boot
systemctl status sshd
sudo systemctl restart sshd
sudo systemctl enable sshd
# Read the daemon's recent log output
journalctl -u sshd -n 20Readers ask
Why is it called a daemon?
The name was coined by programmers at MIT in the 1960s, inspired by Maxwell's demon, an imaginary being in physics that works tirelessly in the background. It has nothing to do with evil spirits.
What is the difference between a daemon and a service?
They mean nearly the same thing. Daemon is the traditional Unix term for a background process, while service is the Windows term and is also used for daemons managed by systemd on Linux.
What is systemd?
systemd is the init system and service manager used by most Linux distributions. It is the first process started by the kernel, and it starts, supervises, and logs the system's daemons.
See also
- ProcessOperating Systems, p. 23A process is a running instance of a program, with its own memory space, resources, and at least one thread of execution managed by the operating system.
- ShellOperating Systems, p. 27A shell is a program that reads commands typed by a user or written in a script and asks the operating system to run them, usually through a text interface.
- Unix SignalOperating Systems, p. 35A Unix signal is a short asynchronous notification the kernel delivers to a process to report an event, such as a stop request, an error, or an expired timer.
- Cron JobBackend & APIs, p. 9A cron job is a command or script that runs automatically on a repeating schedule, such as every night at 2 a.m., defined by a five-field cron expression.
- Background JobBackend & APIs, p. 6A background job is a task that a server runs outside the normal request-response cycle, so slow work like sending emails doesn't make users wait.
- Web ServerBackend & APIs, p. 46A web server is software, or the machine running it, that accepts HTTP requests from browsers and other clients and responds with pages, files, or data.
Spotted a mistake or something missing on this page?Suggest an edit