
Computers with the ability to multitask different processes at once contain a type of process labelled daemon process.
These types of computer programs run in the background, which isn't controlled by a graphical interface or any user input, but rather, by the init system, which also serves as the parent process[1] of most daemons. For easier identification, processes' names end with the letter d to indicate the subjected process is a daemon.
There are a few ways a daemon process can be made, all with different use cases: calling a fork
and having the parent exit [2] creates a daemon process by tricking the shell to thinking the command is finished, the child process obtains a new GID (Group Identifier) but is assigned a different PID (Process Identifier), another method calls a umask
to set the file mode creation mask to a known value, this method is typically preferred when the process makes necessary files. There are more uncommon methods to achieve a daemon process, but are typically too complicated.
Terminology
The term "daemon" comes from MIT's Project MAC[3] on the IBM 7094, labelled after scientist James Maxwell who imagined an interesting physics problem: He Imagined a container divided by a gate which separates the container into 2 equal parts, within the gate exists a hole big enough for one gas molecule, this gate was controlled by a daemon. Maxwell labelled it a "daemon" based off Greek Mythology where a daemon was a supernatural force that would work in the background.
Use-case(s)
Unix-based/like Operating Systems
In such operating systems, daemons serve many functions for every part of the system and are very common. Although not required, many daemons have their parent be the init system, which possesses the PID of 1.
Typically speaking, processes become daemons by being started by either the init system or a start up script.
Controlling a Daemon Process
Using systemctl
:
A user is able to adjust whether a daemon process is enabled or not using the systemctl
command in their preferred shell, if the user wishes to start a daemon, they are able to use the start
function, next to the service name in order to start it up.
$ sudo systemctl start application.service
# There is no output if a application begins succsesfully
# If there is an error:
Failed to start application.service: Unit application.service not found.
# or
Failed to start application.service: Access denied
The user isn't required to add *.service
, the system will automatically look for services that match.
This command also works with stop
, prompting the said service to terminate.
$ sudo systemctl stop application.service
# No Output if successful
# Output on Error(s):
Failed to stop application.service: Unit application.service not loaded.
# or
Failed to stop application.service: Access denied.
If this is a process that is started by the init system at boot, it will begin again on a full reboot if it is enabled or when it is started manually.
References
- ↑ Sep 2nd, 2020, Understanding daemons Unix by Aryaman Sharda: https://digitalbunker.dev/understanding-daemons-unix/
- ↑ Chapter 13. Daemon Processes by Shichao's Notes: https://notes.shichao.io/apue/ch13/
- ↑ Take Our Word For It, Issue 129, Page 2: http://www.takeourword.com/TOW129/page2.html