Introduction to The Linux Kernel

Introduction to The Linux Kernel

Understand the Basics of Linux Kernel

Introduction

Linux is one of the most popular and widely used operating systems in the world. But what makes Linux so powerful and versatile? The answer lies in its core component: the Linux Kernel. The Linux Kernel is the heart of the operating system, responsible for managing the hardware resources, processes, memory, and system calls. In this blog, we will explore the basics of the Linux Kernel, such as its structure, functions, and features. We will also learn how to identify the Linux Kernel version, how memory is separated within the Linux Kernel, and how user programs interact with the Kernel through system calls. By the end of this blog, you will have a better understanding of the Linux Kernel and its role in the Linux operating system.

What is The Linux Kernel?

The kernel is the major component of an operating system and is the core interface between computer's hardware and its processes. It communicates between the two managing resources as efficiently as possible.

If this was hard to understand, then let's see an analogy: an analogy of a college library-

This library has several resources at its disposal: books, reference books, fictional and non-fictional books etc. for students. These resources however are limited in number. These resources are used by the students at the college. The person in charge of the library and a key member of this system is the librarian. let us assume for some minute there was no librarian. we may have handful of students searching through every nook and corner of the library borrowing whatever materials they can lay their hands on. There would be no track of who borrowed what materials and when a material is due to be returned. The books may not be returned to the library by the due date. This mismanaged system could also mean that these resources may not be available for the other students when they really need it. Enter the librarian who ensures that students only get books according to the year they are in limiting one book per student. The librarian keeps track of all the books borrowed and when they are due. The librarian also sends notifications to the students before the due date and make sure resources are returned back so that they can be used by other students subsequently.

The library in this analogy is comparable to a computer operating system. The books, reference materials and other resources are equivalent to the hardware resources, the students are the application processes, the librarian in this example is equivalent to the Linux Kernel.

Kernel's Tasks and Characteristics

The Kernel is responsible for four major tasks.

  1. Memory management: it keeps track of how much memory is used to store what and where.

  2. Process management: Determines which processes can use the CPU when, and for how long.

  3. Device Drivers: It acts as a mediator or an interpreter between the hardware and processes.

  4. System Calls and Security: It receive requests for service from the processes.

The Linux Kernel is Monolithic. This means that the Kernel carries out CPU scheduling, memory management and several other operations by itself.

The Linux Kernel is also Modular, which means it can extend its capabilities through the use of dynamically loaded Kernel modules.

How Does the Linux Kernel work?

One of the important functions of the Linux Kernel is the memory management. We will now see how memory is separated within the Linux Kernel.

Memory is divided into two areas known as Kernel space and User space. These are synonyms to the term Kernel and User mode.

Kernel space is the portion of the memory in which the Kernel executes and provides its services. A process running in the kernel space has unrestricted access to the hardware. As such, it is strictly reserved for running the Kernel code, Kernel extensions and most device drivers.
Going back to the analogy where the Kernel is compared to the librarian, kernel space can be compared to a section of the library where the that only the librarian or administrators of the library has access to. These sections contain books and other reference materials.

On the other hand, all processes running outside the Kernel reside in the user space. which has restricted access to the CPU and memory. Most Unix-like operating systems like Linux come prepackaged with all kinds of utilities, programming languages and graphical tools. These are called User-space applications. This is also often referred to as the Userland. The userland is comparable to areas designated for normal students to read the books and make use of other reference materials.
Examples of user space applications include programs that are written in C, Java, Python, Ruby or any other programming languages.

Let us now look at how programs running in the user space work. all user program function by manipulating data but where does this data live? Most commonly it's stored in memory and on disk. User programs get access to data by making special requests to the Kernel called system calls.
Examples include allocating memory by using variables or opening a file. If we compare this to our analogy, students must make requests to the librarian to borrow specific books from certain sections of the library. The book will only be issued once the librarian approves it.

For example, opening a file such as the /etc/os-release file to see the version of the operating system installed results in a system call. Here the opens the file specified by the pathname. The file is located in the /etc directory which is mounted on a file system created on a block device. Example of other common system calls are close(), readdir(), strlen() and closedir().

How to identify the Linux Kernel version?

The Linux Kernel is constantly updated and improved by the developers and contributors of the Linux community. The Linux Kernel follows a specific naming convention to identify its version and release. The Linux Kernel version consists of four numbers: the Kernel version, the major version, the minor version and the patch level. For example, 4.15.0-72-generic is a Linux Kernel version, where:

  • 4 is the Kernel version, which indicates the major release of the Kernel.

  • 15 is the major version, which indicates the feature updates and changes of the Kernel.

  • 0 is the minor version, which indicates the bug fixes and improvements of the Kernel.

  • 72 is the patch level, which indicates the security updates and patches of the Kernel.

  • generic is the Linux distribution specific information, which indicates the configuration and customization of the Kernel for a particular Linux distribution.

To display the Linux Kernel version of a system, we can use the uname command. The uname command prints the system information, such as the Kernel name, version, release, architecture, etc. For example, uname -r prints the Kernel version and uname -a prints all the system information.

Conclusion

The Linux Kernel is the core component of any Linux-based operating system, responsible for managing the hardware resources and providing services to the user applications. In this blog post, we have learned about the basic concepts of the Linux Kernel, such as its versioning, memory management, process management, device drivers, system calls and security. We have also seen how the Kernel is monolithic and modular, and how it separates the memory into kernel space and user space. By understanding the Linux Kernel, we can appreciate the power and flexibility of Linux as an operating system and explore its potential applications in various domains.