In multitasking computer operating systems, a daemon is a computer program that runs as
a background process, rather than being under the direct control of an interactive user.
Traditionally daemon names end with the letter d: for example, syslogd is the daemon that
implements the system logging facility and sshd is a daemon that services incoming SSH
connections.
In a Unix environment, the parent process of a daemon is often, but not always, the
init process.
A daemon is usually either created 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.
Such procedures are often implemented in various convenience routines such as daemon(3) in
Unix.
Systems often start daemons at boot time and serve the function of responding to network
requests, hardware activity, or other programs by performing some task.
Daemons can also configure hardware, run scheduled tasks, and perform a variety of other tasks.
Terminology The term was coined by the programmers of
MIT's Project MAC.
They took the name from Maxwell's demon, an imaginary being from a famous thought experiment
that constantly works in the background, sorting molecules.
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, with no particular bias towards good or evil.
However, BSD and some of its derivatives have adopted a Christian demon as their mascot
rather than a Greek daemon.
The word daemon is an alternative spelling of demon, and is pronounced DEE-mən.
In the context of computer software, the original pronunciation has drifted to DAY-mən for
some speakers.
Alternate terms for daemon are service, started task, and ghost job.
Creation 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 process as its parent process and has no controlling terminal.
However, more commonly, 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 script or a
SystemStarter script, involves: Dissociating from the controlling tty
Becoming a session leader Becoming a process group leader
Executing as a background task by forking and exiting.
This is required sometimes for the process to become a session leader.
It also allows the parent process to continue its normal execution.
Setting the root directory as the current working directory so that the process does
not keep any directory in use that may be on a mounted file system.
Changing the umask to 0 to allow open(), creat(), et al. operating system calls to provide their
own permission masks and not to depend on the umask of the caller
Closing all inherited files at the time of execution that are left open by the parent
process, including file descriptors 0, 1 and 2 for the standard streams.
Required files will be opened later.
Using a logfile, the console, or null as stdin, stdout, and stderr
If the process is started by a super-server daemon, such as inetd, launchd, or systemd,
the super-server daemon will perform those functions for the process.
Implementation in MS-DOS and Microsoft Windows In the Microsoft DOS environment, daemon-like
programs were implemented as Terminate and Stay Resident software.
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, or the net start and net stop commands.
However, any Windows application can perform the role of a daemon, not just a service,
and some daemons for Windows have the option of running as a normal process.
Implementation in Mac OS On the original Mac OS, 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.
OS X, which is a Unix system, uses daemons.
Etymology According to Fernando J. Corbato who worked
on Project MAC in 1963 his team is the first to use the term daemon.
The use of the term daemon was inspired by Maxwell's demon, an imaginary agent in physics
and thermodynamics that helped to sort molecules.
We fancifully began to use the word daemon to describe background processes which worked
tirelessly to perform system chores.
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:
Many people equate the word "daemon" with the word "demon", implying some kind of satanic
connection between UNIX and the underworld.
This is an egregious misunderstanding.
"Daemon" is actually a much older form of "demon"; daemons have no particular bias towards
good or evil, but rather serve to help define a person's character or personality.
The ancient Greeks' concept of a "personal daemon" was similar to the modern concept
of a "guardian angel"—eudaemonia is the state of being helped or protected by a kindly
spirit.
As a rule, UNIX systems seem to be infested with both daemons and demons.
A further characterization of the mythological symbolism is that a daemon is something which
is not visible yet is always present and working its will.
Plato's 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 which, when it makes itself heard, deters me from what I am about to do
and never urges me on."
Notable service daemons in Unix-like systems
See also
Notes
References
External links Tutorial: Unix Daemons in Perl
How to daemonize in Linux Unix Daemon Server Programming
Linux Daemon Writing HOWTO