All Topics  
Daemon (computer software)

 

   Email Print
   Bookmark   Link






 

Daemon (computer software)



 
 
In Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
 and other computer multitasking
Computer multitasking

In computing, multitasking is a method by which multiple tasks, also known as Computer process, share common processing resources such as a Central processing unit....
 operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
s, a daemon ( or ) is a computer program
Computer program

Computer programs are Instruction for a computer. A computer requires programs to function. Moreover, a computer program does not run unless its instructions are executed by a Central processing unit; however, a program may communicate an Algorithm#Formalization of algorithms to people without running....
 that runs in the background
Background (computer software)

A background process is a computer process that runs with with a relatively low priority, requires little or no input, and generates a minimum of output....
, rather than under the direct control of a user; they are usually initiated as background processes. Typically daemons have names that end with the letter "d": for example, syslogd, the daemon that handles the system log, or sshd, which handles incoming SSH
Secure Shell

Secure Shell or SSH is a network protocol that allows data to be exchanged using a secure channel between two networked devices. Used primarily on Linux and Unix based systems to access shell accounts, SSH was designed as a replacement for TELNET and other Computer security remote Shell s, which send information, notably passwords, in...
 connections.

In a Unix environment, the parent process
Parent process

A parent process is a computer process that has created one or more child processes.In Unix, every process except process 0 is created when another process executes the fork system call....
 of a daemon is often (but not always) the init
Init

init is the program on Unix and Unix-like systems that spawns all other processes. It runs as a daemon and typically has process identifier 1....
 process (PID
Process identifier

In computing, the process identifier is a number used by some operating system kernel s to uniquely identify a computer process.In Unix-like operating systems, the PID of a newly created child process is returned by the Fork system call to the parent process....
=1).






Discussion
Ask a question about 'Daemon (computer software)'
Start a new discussion about 'Daemon (computer software)'
Answer questions from other users
Full Discussion Forum



Encyclopedia


In Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
 and other computer multitasking
Computer multitasking

In computing, multitasking is a method by which multiple tasks, also known as Computer process, share common processing resources such as a Central processing unit....
 operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
s, a daemon ( or ) is a computer program
Computer program

Computer programs are Instruction for a computer. A computer requires programs to function. Moreover, a computer program does not run unless its instructions are executed by a Central processing unit; however, a program may communicate an Algorithm#Formalization of algorithms to people without running....
 that runs in the background
Background (computer software)

A background process is a computer process that runs with with a relatively low priority, requires little or no input, and generates a minimum of output....
, rather than under the direct control of a user; they are usually initiated as background processes. Typically daemons have names that end with the letter "d": for example, syslogd, the daemon that handles the system log, or sshd, which handles incoming SSH
Secure Shell

Secure Shell or SSH is a network protocol that allows data to be exchanged using a secure channel between two networked devices. Used primarily on Linux and Unix based systems to access shell accounts, SSH was designed as a replacement for TELNET and other Computer security remote Shell s, which send information, notably passwords, in...
 connections.

In a Unix environment, the parent process
Parent process

A parent process is a computer process that has created one or more child processes.In Unix, every process except process 0 is created when another process executes the fork system call....
 of a daemon is often (but not always) the init
Init

init is the program on Unix and Unix-like systems that spawns all other processes. It runs as a daemon and typically has process identifier 1....
 process (PID
Process identifier

In computing, the process identifier is a number used by some operating system kernel s to uniquely identify a computer process.In Unix-like operating systems, the PID of a newly created child process is returned by the Fork system call to the parent process....
=1). Processes usually become daemons by forking
Fork (operating system)

In computing, when a Computer_process forks, it creates a copy of itself, which is called a "Child_process." The original process is then called the "Parent_process"....
 a child process and then having their parent process immediately exit, thus causing init to adopt the child process. This is a somewhat simplified view of the process as other operations are generally performed, such as disassociating the daemon process from any controlling tty
Tty (Unix)

tty is a Unix Command that prints to Standard streams the name of the file connected to standard input. The name of the program comes from Teleprinter, abbreviated "TTY"....
. Convenience routines such as daemon(3) exist in some UNIX systems for that purpose.

Systems often start (or "launch") daemons at boot
Booting

In computing, booting is a Bootstrapping process that starts operating systems when the user turns on a computer system. A boot sequence is the initial set of operations that the computer performs when it is switched on....
 time: they often serve the function of responding to network requests, hardware activity, or other programs by performing some task. Daemons can also configure hardware (like devfsd on some Linux
Linux

Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license...
 systems), run scheduled tasks (like cron
Cron

cron is a time-based job scheduler in Unix-like computer operating systems. 'cron' is short for 'chronograph'.This from 1999 describes cron well:...
), 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
Maxwell's demon

Maxwell's demon was an 1867 thought experiment by the Scotland physicist James Clerk Maxwell, meant to raise questions about the possibility of violating the second law of thermodynamics....
, an imaginary being from a famous thought experiment that constantly works in the background, sorting molecules. Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
 systems inherited this terminology. Daemons
Daemon (mythology)

The words daemon, d?mon, are Latinized spellings of the Greek language da???? , used purposely today to distinguish the daemons of Ancient Greek religion, good or malevolent "supernatural beings between mortals and gods, such as inferior divinities and ghosts of dead heroes" , from the Judeo-Christian usage demon, a malignant...
 are also characters in Greek mythology, some of whom handled tasks that the gods could not be bothered with, much as computer daemons often handle tasks in the background that the user cannot be bothered with. BSD
Berkeley Software Distribution

Berkeley Software Distribution is the Unix operating system derivative developed and distributed by the Computer Systems Research Group of the University of California, Berkeley, from 1977 to 1995....
 and some of its derivatives have adopted a daemon as its mascot
BSD Daemon

The BSD daemon, nicknamed Beastie, is the generic mascot of BSD operating systems....
, although this mascot is actually a cute variation of the demon
Demon

In religion, folklore, and mythology a demon is a supernatural being that is generally described as a malevolent spirit. In Christian terms demons are generally understood as fallen angels, formerly of God....
s which appear in Christian
Christian

A Christian is a person who adheres to Christianity, a Monotheism#Christian view religion centered on the life and teachings of Jesus and interpreted by Christians to have been prophesied in the Hebrew Bible/Old Testament....
 artwork.

Pronunciation

The word daemon is an alternative spelling of demon, and taken out of its computer science context, it is . Perhaps due to the relative obscurity of this spelling elsewhere, the computer term daemon is sometimes pronounced incorrectly, .

Types of daemons

In a strictly technical sense, in the Unix world, a process comprises a daemon when it has process number 1 (init
Init

init is the program on Unix and Unix-like systems that spawns all other processes. It runs as a daemon and typically has process identifier 1....
) as its parent process and no controlling terminal. The init process adopts any process whose parent process terminates. The common method for a process to become a daemon involves:
  • Disassociating from the controlling tty
    Tty (Unix)

    tty is a Unix Command that prints to Standard streams the name of the file connected to standard input. The name of the program comes from Teleprinter, abbreviated "TTY"....
  • Becoming a session leader
  • Becoming a process group
    Process group

    In POSIX-conformant operating systems, a process group denotes a collection of one or more process es. Process groups are used to control the distribution of signal s....
     leader
  • Staying in the background
    Background (computer software)

    A background process is a computer process that runs with with a relatively low priority, requires little or no input, and generates a minimum of output....
     by forking
    Fork (operating system)

    In computing, when a Computer_process forks, it creates a copy of itself, which is called a "Child_process." The original process is then called the "Parent_process"....
     and exiting
    Exit (operating system)

    A computer process terminates its execution by making an exit system call. More generally, an exit in a multithreading environment means that a thread of execution has stopped running....
     (once or twice). This is required sometimes for the process to become a session leader. It also allows the parent process to continue its normal execution. This idiom
    Idiom

    An idiom is a phrase whose meaning cannot be determined by the literal definition of the phrase itself, but refers instead to a figurative language meaning that is known only through common use....
     is sometimes summarized with the phrase "fork off and die"
  • Setting the root directory
    Root directory

    In computing file systems, the root directory is the first or top-most directory in a hierarchy. It can be likened to the root of a tree - the starting point where all branches originate....
     ("/") as the current working directory
    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....
     so that the process will not keep any directory in use that may be on a mounted file system (allowing it to be unmounted).
  • Changing the umask
    Umask

    umask is a Command and a Function in POSIX environments which sets the default permission modes for newly created files and directories of the current process....
     to 0 to allow open, creat, et al. calls to provide their own permission masks and not to depend on the umask of the caller
  • Closing all inherited open files at the time of execution that are left open by the parent process, including file descriptors 0, 1 and 2 (stdin, stdout, stderr). Required files will be opened later.
  • Using a logfile, the console
    System console

    The system console, root console or simply console is the text entry and display device for system administration messages, particularly those from the BIOS or boot loader, the Kernel , from the init system and from the syslog....
    , or /dev/null
    /dev/null

    In Unix-like operating systems, /dev/null or the null device is a special file that discards all data written to it , and provides no data to any process that reads from it ....
     as stdin, stdout, and stderr
    Standard streams

    In Unix and Unix-like operating systems, as well as certain programming language interfaces, the standard streams are preconnected input and output channels between a computer program and its environment when it begins execution....


In common Unix usage a daemon may be any background process, whether a child of init or not. Unix users sometimes spell daemon as demon, and most usually pronounce the word that way.

Windows equivalent

In the Microsoft DOS
DOS

DOS, short for "Disk Operating System", is a shorthand term for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions Windows 95, Windows 98, and Windows Me....
 environment, such programs were written as Terminate and Stay Resident
Terminate and Stay Resident

Terminate and Stay Resident is a computer system call in DOS computer operating systems that returns control to the system as if the program has quit, but keeps the program in memory....
 (TSR) software. On Microsoft Windows
Microsoft Windows

Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces ....
 systems, programs called services
Windows Service

On Microsoft Windows operating systems, a Windows service is a long-running executable that performs specific functions and which is designed not to require user intervention....
 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. With Windows NT and later versions, one can configure and manually start and stop Windows services using the Control Panel
Control Panel (Windows)

The Control Panel is a part of the Microsoft Windows graphical user interface which allows users to view and manipulate basic system settings and controls via List of Control Panel applets , such as adding hardware, adding and removing software, controlling user accounts, and changing accessibility options....
 ? Administrative Tools or typing "Services.msc" in the Run command on Start menu
Start menu

The Start Menu and Start Button are graphical user interface elements in the Microsoft Windows line of operating systems, which serve as the central launching point for application and tasks....
.

Mac OS equivalent

On the original Mac OS
Mac OS

Mac OS is the trademarked name for a series of graphical user interface-based operating systems developed by Apple Inc. for their Macintosh line of computer systems....
, optional features and services were provided by files loaded at startup time that patched the operating system; these were known as system extensions
Extension (Mac OS)

On the Apple Macintosh operating system prior to Mac OS X, extensions were small pieces of code that extended the system's functionality. They were run initially at start-up time, and operated by a variety of mechanisms, including trap patching and other code modifying techniques....
 and control panels
Control panel (Mac OS)

A control panel under the Mac OS is a small application software which enabled the user to modify software and hardware settings such as the sound volume and desktop pattern....
. Later versions of classic Mac OS augmented these with fully-fledged faceless background applications
Extension (Mac OS)

On the Apple Macintosh operating system prior to Mac OS X, extensions were small pieces of code that extended the system's functionality. They were run initially at start-up time, and operated by a variety of mechanisms, including trap patching and other code modifying techniques....
: regular applications that ran in the background. To the user, these were still described as regular system extensions.

Mac OS X
Mac OS X

Mac OS X is a line of computer operating systems developed, marketed, and sold by Apple Inc., and since 2002 has been included with all new Macintosh computer systems....
, being a Unix
Unix

Unix is a computer operating system originally developed in 1969 by a group of American Telephone & Telegraph employees at Bell Labs, including Ken Thompson , Dennis Ritchie, Douglas McIlroy, and Joe Ossanna....
-like system, has daemons. There is a category of software called services
Services menu

The Services menu is a user interface element in a computer operating system. The services are programs that accept input from the user selection, process it, and optionally put the result back in the clipboard....
 as well, but these are different in concept from Windows' services.

Etymology

In the general sense, daemon is an older form of the word demon. 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
Satanism

Satanism is a term that refers to a number of related belief systems. Their commonality is that they all feature the symbolism of Satan or similar figures....
 connection between UNIX and the underworld
Underworld

In the study of mythology and religion, the underworld is a generic term approximately equivalent to the lay term afterlife, referring to any place to which newly the dead souls go....
. 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. (p.403)

Sample Program in C on Linux

#include #include #include #include #include #include #include #include #include #include #include /* Change this to whatever your daemon is called */ #define DAEMON_NAME "mydaemon" /* Change this to the user under which to run */ #define RUN_AS_USER "daemon" #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 static void child_handler(int signum) static void daemonize( const char *lockfile ) int main( int argc, char *argv[] )

See also

  • Server
    Server (computing)

    A server is a computer program that provides services to other computer programs , in the same or other computer. The physical computer that runs a server program is also often referred to as server....
  • List of computer term etymologies
    List of computer term etymologies

    This is a list of the origins of computer-related terms or terms used in the computing world . It relates to both computer hardware and computer software....
  • Windows service
    Windows Service

    On Microsoft Windows operating systems, a Windows service is a long-running executable that performs specific functions and which is designed not to require user intervention....
  • Terminate and Stay Resident
    Terminate and Stay Resident

    Terminate and Stay Resident is a computer system call in DOS computer operating systems that returns control to the system as if the program has quit, but keeps the program in memory....
  • User space
    User space

    A conventional operating system usually segregates virtual memory into kernel space and user space. Kernel space is strictly reserved for running the kernel , kernel extensions, and some device drivers....
  • Service Wrapper
    Service Wrapper

    Windows service or daemon programs have to be specially developed. A service wrapper is a program which implements the daemon or service specific requirements and wrap another program thus enabling it to run as a service or daemon....


External links

  • (Debian package)