What Is a Daemon? Background Service Processes
A daemon is a process that runs in the background, detached from any terminal, providing a service such as a database, web server, or scheduler.
Many of the services a build depends on, a database, a Docker engine, a job scheduler, run as daemons: background processes that start up and quietly wait to do their job. In CI, daemons appear when your tests need a service running alongside them, and knowing how they work helps you start and stop them cleanly.
What makes a daemon
A daemon detaches from the controlling terminal and runs in the background, often started at boot. It typically writes to log files rather than the terminal and waits for requests or events.
Examples of daemons
- Database servers like PostgreSQL and MySQL.
- The Docker engine that runs containers.
- cron, which fires scheduled jobs.
- sshd, which accepts remote connections.
Daemons versus foreground processes
A foreground process holds the terminal and you wait for it. A daemon runs independently in the background, so other commands can run while it serves requests. Conventionally daemon names often end in d, like sshd or dockerd.
Starting and stopping daemons
A daemon is usually started by a service manager or by launching it in the background, then stopped by sending it a signal. Scripts must wait for a daemon to be ready before using it, or requests fail.
Daemons in CI
When tests need a database or other service, CI often runs it as a daemon (or a service container) for the job's duration. A common pitfall is talking to the daemon before it is ready, so scripts poll a health check first.
Services on managed runners
Latchkey runners can run service containers as daemons next to your job, and tear them down when the job ends. Waiting on a readiness check before your tests run avoids flaky failures from a not-yet-started service.
Key takeaways
- A daemon is a background process that provides a service, detached from a terminal.
- Databases, the Docker engine, and cron all run as daemons.
- In CI, services run as daemons; wait for readiness before using them.