In
multitasking computer
operating system
An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs.
Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
s, a daemon ( or )
is a
computer program
A computer program is a sequence or set of instructions in a programming language for a computer to execute. Computer programs are one component of software, which also includes documentation and other intangible components.
A computer program ...
that runs as a
background process
A background process is a computer process that runs ''behind the scenes'' (i.e., in the background) and without user intervention. Typical tasks for these processes include logging, system monitoring, scheduling, and user notification. The backgr ...
, 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
The Secure Shell Protocol (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. Its most notable applications are remote login and command-line execution.
SSH applications are based on a ...
connections.
In a
Unix
Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
environment, the
parent process
In computing, a parent process is a process that has created one or more child processes.
Unix-like systems
In Unix-like operating systems, every process except (the swapper) is created when another process executes the fork() system call. Th ...
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
Terminal may refer to:
Computing Hardware
* Terminal (electronics), a device for joining electrical circuits together
* Terminal (telecommunication), a device communicating over a line
* Computer terminal, a set of primary input and output devic ...
(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ó
Fernando José "Corby" Corbató (July 1, 1926 – July 12, 2019) was a prominent American computer scientist, notable as a pioneer in the development of time-sharing operating systems.
Career
Corbató was born on July 1, 1926 in Oakland, Califo ...
, who worked on
Project MAC
Computer Science and Artificial Intelligence Laboratory (CSAIL) is a research institute at the Massachusetts Institute of Technology (MIT) formed by the 2003 merger of the Laboratory for Computer Science (LCS) and the Artificial Intelligence Lab ...
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
Thermodynamics is a branch of physics that deals with heat, work, and temperature, and their relation to energy, entropy, and the physical properties of matter and radiation. The behavior of these quantities is governed by the four laws of the ...
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
Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
systems inherited this terminology. Maxwell's demon is consistent with Greek mythology's interpretation of a
daemon
Daimon or Daemon (Ancient Greek: , "god", "godlike", "power", "fate") originally referred to a lesser deity or guiding spirit such as the daimons of ancient Greek religion and mythology and of later Hellenistic religion and philosophy.
The word ...
as a supernatural being working in the background.
In the general sense, daemon is an older form of the word "demon", from the
Greek
Greek may refer to:
Greece
Anything of, from, or related to Greece, a country in Southern Europe:
*Greeks, an ethnic group.
*Greek language, a branch of the Indo-European language family.
**Proto-Greek language, the assumed last common ancestor ...
δαίμων. In the ''Unix System Administration Handbook''
Evi Nemeth
Evi Nemeth (born June 7, 1940 – missing-at-sea June or July, 2013) was an engineer, author, and teacher known for her expertise in computer system administration and networks. She was the lead author of the "bibles" of system administration: ' ...
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
''Theages'' ( el, Θεάγης) is a dialogue attributed to Plato, featuring Demodocus, Socrates and Theages. There is debate over its authenticity; W. R. M. Lamb draws this conclusion from his opinion that the work is inferior and un-Socratic, ...
'', attributed to
Plato
Plato ( ; grc-gre, Πλάτων ; 428/427 or 424/423 – 348/347 BC) was a Greek philosopher born in Athens during the Classical period in Ancient Greece. He founded the Platonist school of thought and the Academy, the first institution ...
,
Socrates
Socrates (; ; –399 BC) was a Greek philosopher from Athens who is credited as the founder of Western philosophy and among the first moral philosophers of the ethical tradition of thought. An enigmatic figure, Socrates authored no te ...
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
z/OS is a 64-bit operating system for IBM z/Architecture mainframes, introduced by IBM in October 2000. It derives from and is the successor to OS/390, which in turn was preceded by a string of MVS versions.Starting with the earliest:
* O ...
), and ''ghost job'' (XDS
UTS).
After the term was adopted for computer use, it was rationalized as a
backronym
A backronym is an acronym formed from an already existing word by expanding its letters into the words of a phrase. Backronyms may be invented with either serious or humorous intent, or they may be a type of false etymology or folk etymology. The ...
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
A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and pro ...
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 SystemStarter is a system program in Mac OS X, started by Mac OS X's BSD-style init prior to Mac OS X v10.4 and by launchd in Mac OS X v10.4 and later releases, that starts system processes specified by a set of property list
In the macOS, iOS, ...
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.
** Creating a new session and becoming the session leader of that session.
** Becoming a
process group
In a POSIX-conformant operating system, a process group denotes a collection of one or more processes.
Among other things, a process group is used to control the distribution of a signal;
when a signal is directed to a process group, the signal i ...
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
In computing, the working directory of a process is a directory of a hierarchical file system, if any, dynamically associated with each process. It is sometimes called the current working directory (CWD), e.g. the BSD getcwd function, or just cur ...
so that the process does not keep any directory in use that may be on a
mounted
Mount is often used as part of the name of specific mountains, e.g. Mount Everest.
Mount or Mounts may also refer to:
Places
* Mount, Cornwall, a village in Warleggan parish, England
* Mount, Perranzabuloe, a hamlet in Perranzabuloe parish, C ...
file system (allowing it to be unmounted).
* Changing the
umask
In computing, umask is a command (computing), command that determines the settings of a Mask (computing), mask that controls how file permissions are set for newly created files. It may also affect how the file permissions are changed explicitly. ...
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
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 ...
(
stdin
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 ...
,
stdout
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 ...
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
In computing, logging is the act of keeping a log of events that occur in a computer system, such as problems, errors or just information on current operations. These events may occur in the operating system or in other software. A message or lo ...
, 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
MS-DOS ( ; acronym for Microsoft Disk Operating System, also known as Microsoft DOS) is an operating system for x86-based personal computers mostly developed by Microsoft. Collectively, MS-DOS, its rebranding as IBM PC DOS, and a few oper ...
environment, daemon-like programs were implemented as terminate-and-stay-resident program
A terminate-and-stay-resident program (commonly TSR) is a computer program running under DOS that uses a system call to return control to DOS as though it has finished, but remains in computer memory so it can be reactivated later. This technique ...
s (TSR).
Windows NT
On Microsoft Windows NT
Windows NT is a proprietary graphical operating system produced by Microsoft, the first version of which was released on July 27, 1993. It is a processor-independent, multiprocessing and multi-user operating system.
The first version of Window ...
systems, programs called Windows service
In Windows NT operating systems, a Windows service is a computer program that operates in the background. It is similar in concept to a Unix daemon. A Windows service must conform to the interface rules and protocols of the Service Control Manager ...
s 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
Windows 2000 is a major release of the Windows NT operating system developed by Microsoft and oriented towards businesses. It was the direct successor to Windows NT 4.0, and was Software release life cycle#Release to manufacturing (RTM), releas ...
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 Service Control Manager (SCM) is a special system process under the Windows NT family of operating systems, which starts, stops and interacts with Windows service processes. It is located in the %SystemRoot%\System32\services.exe executable. Service ...
( command), the and commands or the PowerShell
PowerShell is a task automation and configuration management program from Microsoft, consisting of a command-line shell (computing), shell and the associated scripting language. Initially a Windows component only, known as Windows PowerShell, it ...
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. 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
macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
, which is a Unix
Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
system, uses daemons but uses the term "services" to designate software that performs functions selected from the Services menu
The Services menu (or simply Services) is a user interface element in macOS. The services are programs that accept input from the user selection, process it, and optionally put the result back in the clipboard. The concept originated in the NeXTSTE ...
, rather than using that term for daemons, as Windows does.
See also
* List of computer term etymologies
This is a list of the origins of computer-related terms or terms used in the computing world (i.e., a list of computer term etymologies). It relates to both computer hardware and computer software.
Names of many computer terms, especially compu ...
* List of Unix daemons
* Service wrapper A service wrapper is a computer program that wraps arbitrary programs thus enabling them to be installed and run as Windows Services or Unix daemons, programs that run in the background, rather than under the direct control of a user. They are ofte ...
* 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
A terminate-and-stay-resident program (commonly TSR) is a computer program running under DOS that uses a system call to return control to DOS as though it has finished, but remains in computer memory so it can be reactivated later. This technique ...
* User space
A modern computer operating system usually segregates virtual memory into user space and kernel space. Primarily, this separation serves to provide memory protection and hardware protection from malicious or errant software behaviour.
Kernel ...
* Web service
* Windows service
In Windows NT operating systems, a Windows service is a computer program that operates in the background. It is similar in concept to a Unix daemon. A Windows service must conform to the interface rules and protocols of the Service Control Manager ...
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)