Software

Linux daemons, what they are and why they are actually angels

Linux daemons, what they are and why they are actually angels

In the vast landscape of computing, there are elements that work tirelessly behind the scenes to ensure the correct functioning of operating systems. Among these, i daemon they represent an essential cog, playing a fundamental role in monitoring and managing specific subsystems without requiring direct user intervention.

The concept of daemon (read “demon“) is rooted in the environment GNU/Linux: for example, there are specific components that deal with the monitoring and management of printing services, while a network daemon carries out the task of verifying the correct functioning of aspects related to the networking. Daemons perform certain actions at designated times or in response to specific events. There are many of them on a Linux system, each designed specifically to police a specific part of the system.

For those coming from the Windows world, daemons are known as “services“. Even in macOS systems, which use a hybrid kernel derived from UNIX, daemons are used: however, they take the name of agents.

Where does the term daemon come from?

The term “daemon” has ancient origins and its etymology is rich in meanings and interpretations. Initially, in Greek mythology, a “daimon” was considered a divine spirit or higher intelligence that acted as an intermediary between gods and humans. These spirits were often associated with some sort of guidance or inspiration, and could take on many different forms and functions.

In computing, the term “daemon” was adopted in 1963 with the MAC project Massachusetts Institute of Technology (MIT), to indicate any system process that monitor other activities and performs predefined actions based on their behavior. The acronym “Disk And Execution MONitor” is much newer and is still commonly used today.

In short, a “daemon” is a program or process that operates in backgroundoften performing tasks that are useful or essential to the system’s operation, such as monitoring services or managing resources.

How to check what components are running on a Linux system

If you are using a Linux machine, to locate the running daemon you can analyze the list of running processes using commands like ps, top e htop. Processes ending with the letter “d” are often daemons that take care of a specific task.

The command pstree shows the processes currently running on the system in the form of tree diagram. By running the pstree command from the terminal, you can get a complete list of running processes, including daemons. Thanks to this effective graphical representation, you can have a clear view of what is happening in your system.

Here, below, is a example simplified than a possible output of the command pstree:

systemd─┬─ModemManager───2*[{ModemManager}]
        ├─NetworkManager─┬─dhclient
        │                └─2*[{NetworkManager}]
        ├─accounts-daemon───2*[{accounts-daemon}]
        ├─acpid
        ├─avahi-daemon───avahi-daemon
        ├─bluetoothd
        ├─cron
        ├─cups-browsed
        ├─2*[cupsd]
        ├─dbus-daemon
        ├─2*[gnome-keyring-d───5*[{gnome-keyring-d}]]
        ├─gpg-agent
        ├─gvfsd───────────2*[{gvfsd}]
        ├─ibus-daemon─┬─ibus-dconf───2*[{ibus-dconf}]
        │             ├─ibus-engine-sim───2*[{ibus-engine-sim}]
        │             └─2*[{ibus-daemon}]
        ├─2*[irqbalance───{irqbalance}]
        ├─lightdm─┬─Xorg───2*[{Xorg}]
        │         ├─lightdm─┬─upstart─┬─upstart-dbus-bridg───dbus-daemon
        │         │         │         └─2*[{upstart}]
        │         │         └─upstart-udev-br
        │         ├─lightdm─┬─sh───Xorg───2*[{Xorg}]
        │         │         ├─2*[upstart───2*[{upstart}]]
        │         │         ├─upstart-dbus-bridg───dbus-daemon
        │         │         └─upstart-udev-br
        │         ├─lightdm─┬─upstart─┬─upstart-dbus-bridg───dbus-daemon
        │         │         │         └─2*[{upstart}]
        │         │         └─upstart-udev-br
        │         ├─lightdm───lightdm─┬─gnome-session─┬─applet.py───2*[{applet.py}]
        │         │                     │               ├─deja-dup-monito───2*[{deja-dup-monito}]
        │         │                     │               ├─evolution-calen───4*[{evolution-calen}]
        │         │                     │               ├─evolution-sourc───2*[{evolution-sourc}]
        │         │                     │               ├─gnome-power-man───2*[{gnome-power-man}]
        │         │                     │               ├─gnome-session-b───2*[{gnome-session-b}]
        │         │                     │               ├─gnome-settings-───3*[{gnome-settings-}]
        │         │                     │               ├─gnome-shell-cal───5*[{gnome-shell-cal}]
        │         │                     │               ├─gnome-shell-ove───3*[{gnome-shell-ove}]
        │         │                     │               ├─gnome-terminal-───2*[{gnome-terminal-}]
        │         │                     │               ├─gnome-wm───2*[{gnome-wm}]
        │         │                     │               ├─nautilus───2*[{nautilus}]
        │         │                     │               ├─ssh-agent
        │         │                     │               ├─zeitgeist-datah───{zeitgeist-datah}
        │         │                     │               └─3*[{gnome-session}]
        │         │                     ├─{lightdm}
        │         │                     ├─{upstart}
        │         │                     └─{upstart-udev-br}
        │         ├─{lightdm}
        │         └─{lightdm}
        ├─2*[nmbd]
        ├─polkitd───{polkitd}
        ├─rsyslogd───3*[{rsyslogd}]
        ├─rtkit-daemon───2*[{rtkit-daemon}]
        ├─systemd-journal
        ├─systemd-logind
        ├─systemd-udevd
        ├─udisksd───4*[{udisksd}]
        ├─upowerd───2*[{upowerd}]
        ├─whoopsie───2*[{whoopsie}]
        ├─wpa_supplicant
        └─xdg-permission-───2*[{xdg-permission-}]

The one presented is only a partial example but it shows the hierarchical structure of processes on the system, with the daemon systemd (more on that later) as the root process and its subprocesses listed below it. Each process is represented with its name, followed by any child processes.

Il forking is a key concept in process creation in Linux. Usually, though create a process, you make a copy of an existing process to generate a new child process. The process of initialization is responsible for creating daemons: i fork carried out in succession allow you to start the processes necessary for the correct functioning of the system.

Some examples of daemons

We mentioned earlier that Linux daemons are identifiable through the suffix “d”. Below are some examples of daemons that might be running on a Linux system:

  • systemd: A daemon that has the task of unifying the configuration and behavior of services between the various Linux distributions.
  • rsyslogd: Used for logging system messages, it represents an advanced version of syslogd, with numerous additional features.
  • crond: Daemon widely used to schedule the execution of specific tasks on the system. For example software updates and automated procedures.
  • udisksd: To supervise the mounting, dismounting and formatting of storage devices, this additional daemon is used.
  • logind: A rather agile and compact daemon that manages user logins and sessions in various ways.
  • httpd: HTTP service handler, commonly used with web server software such as Apache.
  • sshd: Daemon responsible for managing the SSH service, used on practically all servers that accept SSH connections.
  • ftpd: Manages the FTP service (File Transfer Protocol), widely used for transferring files between computers.

How to manage daemons

To automatically start a daemon during the system bootyou can create a dedicated system unit systemd or use custom startup scripts by placing them in the directory /etc/init.d/.

Per monitor the status of daemons, you can use commands like systemctl status e ps auxor using more advanced monitoring tools like Nagios o Zabbix.

Restarting and stopping each daemon can be requested using commands, respectively systemctl restart e systemctl stopor via custom startup scripts.

I log daemons are typically managed by syslog o rsyslog: Their creation can be set via specific specific configuration files.

During the application of the software updates, it is important to ensure that these components are stopped and restarted correctly, so as not to cause interruptions in service. Think for example of Web servers and databases that contribute to the correct provision of a large number of…

Leave a Reply

Your email address will not be published. Required fields are marked *