Daemon
A daemon is a background process that runs without a controlling terminal and provides a service, usually started at boot. Examples include sshd, nginx, and cron.
Understanding Linux Daemons
What Is a Daemon in Linux?
A daemon is a long-running background process with no terminal attached. It starts at boot, waits for work (a connection, a schedule, an event), and keeps running after you log out. By convention many daemon names end in "d": sshd, crond, systemd-journald. Some, like nginx and postgres, do not follow that naming.
How Daemons Start: Old Way vs systemd
Traditional daemons detached themselves with a "double fork": fork, exit the parent, call setsid() to leave the terminal session, fork again, then redirect stdin, stdout, and stderr. With systemd none of that is needed. You write a unit file, systemd runs the program in the foreground, tracks its PID, restarts it, and captures its output in the journal.
Common Production Daemons
sshd SSH servernginx Web server and reverse proxypostgres PostgreSQL database serverredis-server Redis cachedockerd Docker daemonkubelet Kubernetes node agentjournald Log collection (part of systemd)crond Job schedulerfail2ban Brute-force protectionauditd Security audit loggingPractical Commands for Managing Daemons
systemctl list-units --type=service --state=running # running daemonssystemctl list-unit-files --type=service --state=enabled # start at bootsystemctl is-active nginxsystemctl is-enabled nginxsystemctl status nginx # PID, memory, recent logssystemctl list-units --type=service --state=failed journalctl -u nginx -f # follow logsjournalctl -u nginx --since today sudo systemctl mask telnet.socket # block it from starting at allsudo systemctl unmask telnet.socketTroubleshooting Daemons
| Symptom | Command | What to Look For |
|---|---|---|
| Will not start | journalctl -u name -n 30 |
Startup error |
| High memory | systemctl status name |
Memory line |
| Duplicate instances | pgrep -c name |
Count above expected |
| Cannot bind port | journalctl -u name | grep -i bind |
Port in use or denied |
Tip
systemctl maskis stronger thandisable. A disabled service will not start at boot but can still be started by another unit; a masked one is linked to/dev/nulland cannot be started until unmasked.
RememberA daemon has no terminal, so its output goes nowhere unless configured. Under systemd it lands in journald automatically. If a daemon seems silent, check where its output is being sent.
Frequently Asked Questions
How is a daemon different from a process started with &?
A job started with `&` is still tied to your shell session and can receive SIGHUP when the terminal closes. A daemon has its own session with no controlling terminal and is re-parented to PID 1, so it survives logout.
Should I still write my own double-fork daemon code?
Rarely. systemd supervises a foreground process with `Type=simple`, handles restarts and logging, and reaps zombies reliably, so hand-rolled daemonizing is mostly legacy practice.
What is the difference between disabling and masking a service?
Disabling only removes the boot-time link, so something else can still start it. Masking makes it impossible to start by any means until you unmask it.