
In
multitasking computer
operating systems, a daemon ( or )
is a
computer program that runs as a
background process, rather than being under the direct control of an interactive user. Traditionally, the process names of a daemon end with the letter ''d'', for clarification that the process is in fact a daemon, and for differentiation between a daemon and a normal computer program. For example, is a daemon that implements system logging facility, and is a daemon that serves incoming
SSH connections.
In a
Unix environment, the
parent process of a daemon is often, but not always, the
init
In Unix-based computer operating systems, init (short for ''initialization'') is the first process started during booting of the computer system. Init is a daemon process that continues running until the system is shut down. It is the direct ...
process. A daemon is usually created either by a process
forking a child process and then immediately exiting, thus causing init to adopt the child process, or by the init process directly launching the daemon. In addition, a daemon launched by forking and exiting typically must perform other operations, such as dissociating the process from any controlling
terminal (tty). Such procedures are often implemented in various convenience routines such as ''daemon(3)'' in Unix.
Systems often start daemons at
boot
A boot is a type of footwear. Most boots mainly cover the foot and the ankle, while some also cover some part of the lower calf. Some boots extend up the leg, sometimes as far as the knee or even the hip. Most boots have a heel that is cle ...
time that will respond to network requests, hardware activity, or other programs by performing some task. Daemons such as
cron
The cron command-line utility is a job scheduler on Unix-like operating systems. Users who set up and maintain software environments use cron to schedule jobs (commands or shell scripts), also known as cron jobs, to run periodically at fixed ti ...
may also perform defined tasks at scheduled times.
Terminology
The term was coined by the programmers at
MIT's Project MAC. According to
Fernando J. Corbató, who worked on
Project MAC in 1963, his team was the first to use the term daemon, inspired by
Maxwell's demon
Maxwell's demon is a thought experiment that would hypothetically violate the second law of thermodynamics. It was proposed by the physicist James Clerk Maxwell in 1867. In his first letter Maxwell called the demon a "finite being", while the ' ...
, an imaginary agent in physics and
thermodynamics that helped to sort molecules, stating, "We fancifully began to use the word daemon to describe background processes that worked tirelessly to perform system chores".
Unix systems inherited this terminology. Maxwell's demon is consistent with Greek mythology's interpretation of a
daemon as a supernatural being working in the background.
In the general sense, daemon is an older form of the word "demon", from the
Greek δαίμων. In the ''Unix System Administration Handbook''
Evi Nemeth states the following about daemons:
A further characterization of the mythological symbolism is that a daemon is something that is not visible yet is always present and working its will. In the ''
Theages'', attributed to
Plato,
Socrates describes his own personal daemon to be something like the modern concept of a moral conscience: "The favour of the gods has given me a marvelous gift, which has never left me since my childhood. It is a voice that, when it makes itself heard, deters me from what I am about to do and never urges me on".
In modern usage, the word ''daemon'' is pronounced . In the context of computer software, the original pronunciation has drifted to for some speakers.
Alternative terms for ''daemon'' are ''
service
Service may refer to:
Activities
* Administrative service, a required part of the workload of university faculty
* Civil service, the body of employees of a government
* Community service, volunteer service for the benefit of a community or a pu ...
'' (used in Windows, from Windows NT onwards, and later also in Linux), ''started task'' (IBM
z/OS), and ''ghost job'' (XDS
UTS).
After the term was adopted for computer use, it was rationalized as a
backronym for Disk And Execution MONitor.
Daemons that connect to a computer network are examples of
network service
In computer networking, a network service is an application running at the network application layer and above, that provides data storage, manipulation, presentation, communication or other capability which is often implemented using a client� ...
s.
Implementations
Unix-like systems
In a strictly technical sense, a Unix-like system process is a daemon when its parent process terminates and the daemon is assigned the
init
In Unix-based computer operating systems, init (short for ''initialization'') is the first process started during booting of the computer system. Init is a daemon process that continues running until the system is shut down. It is the direct ...
process (process number 1) as its parent process and has no controlling terminal. However, more generally, a daemon may be any background process, whether a child of the init process or not.
On a Unix-like system, the common method for a process to become a daemon, when the process is started from the
command line or from a startup script such as an
init
In Unix-based computer operating systems, init (short for ''initialization'') is the first process started during booting of the computer system. Init is a daemon process that continues running until the system is shut down. It is the direct ...
script or a
SystemStarter script, involves:
* Optionally removing unnecessary variables from environment.
* Executing as a
background task by
forking and
exiting (in the parent "half" of the fork). This allows daemon's parent (shell or startup process) to receive exit notification and continue its normal execution.
* Detaching from the invoking session, usually accomplished by a single operation,
setsid()
:
** Dissociating from the controlling
tty
TTY may refer to:
Communications and technology
* Teleprinter or teletypewriter (TTY), an electromechanical typewriter paired with a communication channel
** Sometimes used more generally for any type of computer terminal
** Sometimes used for a v ...
.
** Creating a new session and becoming the session leader of that session.
** Becoming a
process group leader.
* If the daemon wants to ensure that it will not acquire a new controlling tty even by accident (which happens when a session leader without a controlling tty opens a free tty), it may fork and exit again. This means that it is no longer a session leader in the new session, and cannot acquire a controlling tty.
* Setting the
root directory
In a computer file system, and primarily used in the Unix and Unix-like operating systems, the root directory is the first or top-most directory in a hierarchy. It can be likened to the trunk of a tree, as the starting point where all branches ...
() as the current
working directory so that the process does not keep any directory in use that may be on a
mounted file system (allowing it to be unmounted).
* Changing the
umask to 0 to allow
open()
,
creat()
, and other operating system calls to provide their own permission masks and not to depend on the umask of the caller.
* Redirecting
file descriptor
In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket.
File descriptors typically have ...
s 0, 1 and 2 for the
standard streams (
stdin,
stdout and
stderr
In computer programming, standard streams are interconnected input and output communication channels between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin ...
) to or a
logfile, and closing all the other file descriptors inherited from the parent process.
If the process is started by a
super-server
A super-server or sometimes called a service dispatcher is a type of daemon run generally on Unix-like systems.
Usage
A super-server starts other servers when needed, normally with access to them checked by a TCP wrapper. It uses very few reso ...
daemon, such as , , or , the super-server daemon will perform those functions for the process,
except for old-style daemons not converted to run under and specified as
[ and "multi-threaded" datagram servers under .][
]
MS-DOS
In the Microsoft DOS environment, daemon-like programs were implemented as terminate-and-stay-resident programs (TSR).
Windows NT
On Microsoft Windows NT systems, programs called Windows services perform the functions of daemons. They run as processes, usually do not interact with the monitor, keyboard, and mouse, and may be launched by the operating system at boot time. In Windows 2000 and later versions, Windows services are configured and manually started and stopped using the Control Panel, a dedicated control/configuration program, the Service Controller component of the Service Control Manager ( command), the and commands or the PowerShell scripting system.
However, any Windows application can perform the role of a daemon, not just a service, and some Windows daemons have the option of running as a normal process.
Classic Mac OS and macOS
On the classic Mac OS
Mac OS (originally System Software; retronym: Classic Mac OS) is the series of operating systems developed for the Macintosh family of personal computers by Apple Computer from 1984 to 2001, starting with System 1 and ending with Mac OS 9. The ...
, optional features and services were provided by files loaded at startup time that patched the operating system; these were known as system extensions and control panels
Control may refer to:
Basic meanings Economics and business
* Control (management), an element of management
* Control, an element of management accounting
* Comptroller (or controller), a senior financial officer in an organization
* Controlling ...
. Later versions of classic Mac OS augmented these with fully fledged faceless background applications: regular applications that ran in the background. To the user, these were still described as regular system extensions.
macOS, which is a Unix system, uses daemons but uses the term "services" to designate software that performs functions selected from the Services menu, rather than using that term for daemons, as Windows does.
See also
* List of computer term etymologies
* List of Unix daemons
This is a list of Unix daemons that are found on various Unix-like operating systems. Unix daemons typically have a name ending with a ''d''.
See also
*List of Unix commands
This is a list of Unix commands as specified by IEEE Std 1003.1- ...
* Service wrapper
* Software bot
A software bot is a type of software agent in the service of software project management and software engineering. A software bot has an identity and potentially personified aspects in order to serve their stakeholders. Software bots often compose ...
* Terminate and stay resident program
* User space
* Web service
* Windows service
References
External links
* {{Webarchive, url=https://web.archive.org/web/20191030233137/http://www.enderunix.org/docs/eng/daemon.php , title=Unix Daemon Server Programming , date=2019-10-30
Linux Daemon Writing HOWTO
Process (computing)
Servers (computing)