An operating system (OS) kernel is one of the challenging topics in computer science.
In this tutorial, we’re going to briefly define what the OS kernel is and give some information about its purposes.
The kernel is the most important part of the operating system. It is the primary interface between the hardware and the processes of a computer. The kernel connects these two in order to adjust resources as effectively as possible.
It is named a kernel because it operates inside the OS, just like a seed inside a hard shell. The figure below shows its place in an OS. It controls all of the main functions of the hardware, whether it’s a tablet, desktop, server, or any other kind of device:
The kernel is one of the initial programs loaded up on memory before the boot loader. The boot loader is responsible for translating instructions for the central processing unit. It manages memory as well as peripherals such as keyboards and monitors.
3. Purposes of the Kernel
The kernel has several important jobs, such as process and memory management, disk storage, and low-level networking. We can summarize the main purposes of the kernel as below:
- Determines which process is the next process on the central process unit (CPU), when, and how long
- Monitors how much memory is being used to store what and where
- Serves as an interpreter between the hardware and processes
- Receives requests for service from the processes via system calls
If the developers implement the kernel appropriately, it is out of sight of the user. It operates in its own area called the kernel space. It allocates memory and monitors where everything is stored in the kernel space.
The user space is the environment where the user sees files and web browsers. These programs communicate with the kernel using a system call interface.
4. Where is the Kernel?
If we try to visualize where the kernel fits in a machine, we can think of the machine as having three layers:
User processes: User processes actually create the userspace. However, these processes are the applications that the kernel controls. The kernel also enables these processes to communicate with each other. It uses inter-process communication (IPC) mechanisms to enable communication between processes.
Kernel: As we can see, it’s right in the middle of the layers. It’s the core of the OS.
Hardware: It’s the physical machine, the base of the system. It consists of memory, the processor or the central processing unit (CPU), and input/output (I/O) components such as graphics, storage, and networking. The CPU executes computations and reads and writes to memory.
There are two modes for the code executed by the system on a CPU: kernel mode and user mode. While the code is running in kernel mode, it has unlimited access to the hardware. However, if the code is running in user mode, it has limited access to the CPU and the memory.
These two modes provide some critical and complicated operations. For example, it helps privilege separation for security. Actually, this means that if a process fails in user mode, kernel mode minimizes the error, and it can recover the process.
There are so many kernel types, such as the monolithic kernel, microkernel, exokernel, hybrid kernel, and nano kernel. The main difference between the monolithic kernel and microkernel is related to the system calls and their kernel spaces.
For example, most Unix kernels are monolithic. Each kernel layer integrates into the entire kernel program and runs in kernel mode. On the other hand, microkernel operating systems only require a small number of kernel functions such as an IPC mechanism and, a basic scheduler.
In this article, we gave the definition of the kernel in OS. Then, we briefly gave the information about its purposes. After that, we visualized where the kernel fits in a machine, and we listed some of the kernel types.