Learn Linux

Everything about Daemons in Linux

Everything about Daemons in Linux

Since the Linux operating system is characterized as a multitasking operating system, a daemon is, by definition, a program that continuously executes as a background process. In short, the execution of this process is not dependent on an active user's system interaction. A normal system user cannot control the periodic execution of a daemon process.

The naming convention that defines most daemon processes is the one letter 'suffix' d. This naming convention makes it possible to differentiate between normal system processes and daemon-powered processes. For example, sshd is a daemon process responsible for the management of incomingSSH connections. Another daemon process example issyslogd. It is responsible for the Linux system logging facility.

In a Linux environment, the launch of daemons is at boot time. Since the Linux system is a perfect Unix clone, an init process qualifies as the parent process to a daemon. To start and stop daemons on your Linux operating system, you first need to access the/etc/init.d scripts directory on your OS.

Common daemons functions

Useful Linux service daemons

Whether you are a beginner, intermediate, or expert user in the Linux operating system world, you will never fail to familiarize yourself with either of the above-listed daemons as you advance your skills and expertise within this OS environment.

Starting/stopping/restarting daemons: the terminal-based approach

Now that you have a list of useful Linux daemons to memorize and explore, the first thing you need to know is how to start, stop, or restart these daemons. With your Linux Terminal launched, consider the following syntax rules to start, stop, and restart a daemon on your Linux Operating System.

service preferred-daemon-name start service preferred-daemon-name stop  service preferred-daemon-name restart

Replace the preferred-daemon-name syntax argument with the Linux system daemon name of your choice. You can pick one from the daemon list highlighted above as long as it is active or already defined on your Linux system. For example, we can implement the practical usage of the above syntax by trying to start, stop, and restart adaemon. Navigate to the /etc/init.d directory on your terminal for the list of available daemons on your Linux system.

listing active daemons on your Linux system.png

how to start, stop, and restart a daemon service on your Linux system.png

Listing your Linux systems' daemons

A more effective way of noting the available daemons on your Linux system instead of navigating to the /etc/init.d directory is to list all the defined active and inactive daemons from that directory with a single command. The following command is effective in achieving this objective.

$ service -status-all

listing all the daemons on your Linux operating system.png

The braced positive [+] and negative [-] signs preceding the listed daemon names imply that they are either active or inactive, respectively.

Working with user-defined daemons

Specific rules or protocols must be followed to create and implement a user-defined daemon successfully. These protocols help you to comprehend the execution of daemons on any Linux environment fully. Daemons are also flexible enough to interface with kernel modules through system calls. This daemon functionality stretch supports its interaction with hardware devices like PDAs (Personal Digital Assistants), printers, and viable external controller boards. The building blocks of daemons also contribute to the characteristic power and flexibility of the Linux operating system.

A relatable daemon implementation using Python is carefully demonstrated and documented by Sander Marechal. Be keen to follow the execution order in creating this daemon. First off, your Linux system needs the installation of Python packages to develop daemons successfully. To install Python, you can use the following command.

$ sudo apt install python3-pip python3-dev

The link to Sander Marechal's authoredPython daemon code also offers a refined Python 3 code version. It would help if you considered implementing it to understand better how daemons work.

If you are unsure whether you have Python installed, run the following command on your Linux terminal.

$ python3 --version

The purpose of any daemon

Since a single daemon is dedicated to handling a specific task, it should execute it to perfection. The task in question can be as simple as creating a report and sending it to an admin through sendmail or as complex as managing multiple domains linked to multiple mailboxes. At some point, the daemon you are going to create will have to talk to other existing daemons.

user-to-daemon interaction

It is discouraged to have the system user and the created daemon communicate directly. If it is necessary for the daemon, you create to communicate with a system user. This communication can be facilitated through something like a GUI interface. This communication platform can either have GTK+ GUI complexity or signal set simplicity.

Creating your daemon

Numerous approaches support the creation of daemons. For example, you can use your command-line interface to daemonize a Python script as follows:

$ python my_python_script.py &

You can save Sander Marechal's authored Python3 daemon code on a Python file and daemonize it with the above command. While the above terminal command will easily create a daemon for you, you will have to deal with challenges such as unpredictable terminal outputs. These challenges depend on how well you refactored your Python daemon code. Also, the above approach does not support assigning PID lock files to specific daemons. It makes it impossible to control any daemon as most of them will be executing instantaneously. On the other hand, if you only need a simple daemon, the above-mentioned approach will give you the desired daemon results.

Daemon basic structure

Before a daemon executes or performs an intended function, it will have to consider some preconceived rules leading to its execution. You can think of these rules as low-level housework leading to its actual task. These rules can be broken down into the following steps.

More on daemons example implementations can be found on GitHub.

En İyi 5 Oyun Yakalama Kartı
YouTube'da oyun akışlarını hepimiz gördük ve sevdik. PewDiePie, Jakesepticye ve Markiplier, oyun deneyimlerini yükleyerek ve izleyicileri en yeni oyun...
Linux'ta Oyun Nasıl Geliştirilir
On yıl önce, pek çok Linux kullanıcısı en sevdikleri işletim sisteminin bir gün ticari video oyunları için popüler bir oyun platformu olacağını tahmin...
Open Source Ports of Commercial Game Engines
Free, open source and cross-platform game engine recreations can be used to play old as well as some of the fairly recent game titles. This article wi...