What is kernel?

A computer system takes command from the user through the operating system to perform a task. It can be in a graphical or command-line interface. But the computer system can only understand binary language. So, the translation between simple command or instruction into binary language is done by the core component of the operating system called Kernel.
The kernel is not an operating system it is a core part of any operating system. Kernel plays a mediator role between hardware and software systems.
A kernel is the most critical element. If the kernel fails, the rest of the system fails. The kernel is responsible for managing tasks like process management, CPU resource scheduling, disk management, memory management, etc. The actual size of a kernel varies from machine to machine, depending upon what features are compiled.
Whenever a system starts, the kernel is the first program that is loaded into the memory area after the bootloader. It remains in memory until the system power is on.

The functions of Kernel
The kernel controls and manages all primary tasks of OS.
Process management: A process is an instance of a computer program that is being executed. The kernel manages the creation, execution, and termination of the process to avoid the deadlock situation. The process management is very important for the better functionality of an operating system and all this is handled by the kernel.
Memory management: All processes need some memory space. So, the kernel allocates the memory to every process. The kernel keeps track of the memory about which part of the memory space is currently allocated and which part of the memory space is available for other processes.
Device management: The kernel includes device driver support for a large number of pc hardware devices like graphics cards, network cards, hard disks, etc.
Interrupt handling: While executing the processes, sometimes the condition occurs where some tasks need more priority and need to be handled first. In such cases, the kernel has to interrupt the execution of current processes and handled the task which has more priority. 
I/O communication: The kernel is also responsible for handling input and output devices through device drivers. A device driver is a computer software program that enables the operating system to interact with the hardware devices. So, all the instruction that the system receives from the user and the output provided to the user via different applications is handled by the kernel.
Inter-process communication (IPC): The kernel provides a method for synchronization and communication between two processes with each other in order to perform a task and share data. There are various approaches of IPC such as FIFO, message queues, shared memory, semaphores, signals, pipes.

Types of Kernel
Monolithic kernel: In a monolithic kernel user services and kernel services are reside in the same memory area.

It increases the size of the kernel as well as increases the size of the operating system. As there is no separate user space and kernel space in the memory area, so the execution of the process is faster in the monolithic kernel.
This kernel provides various services such as CPU scheduling, memory management, file management, process scheduling, and other functions through system calls.  Due to the large size, it is difficult to maintain the kernel.
Microkernel: In microkernel kernel user services and kernel, services reside in a different memory area. It decreases the size of a kernel as well as the size of the operating system because the user services are store in the user space and kernel services are store in kernel address space.
The execution of the process is slower in the microkernel. In microkernel architecture maintenance is easier and patches can be tested separate instances from the production instance. 
Hybrid kernel: Hybrid kernel architecture is a combination of microkernel and monolithic kernel architecture. This kernel has speed and simpler design of monolithic kernel with the modularity of microkernel.
A hybrid kernel runs some services in the kernel space in order to run code more quickly than it would be in user space and also to reduce some performance overhead because it has traditional code from microkernel while still running kernel code as the server in the user space.
Nanokernel: In a nanokernel, the kernel code is very small. It executes code in the privileged mode of the hardware without system services.
Exokernel: Exokernel is developed by MIT (Massachusetts Institute of Technology). It is an operating system kernel that seeks to provide application-level management of hardware resources. The exokernel is designed not to implement all the abstractions but to impose as few abstractions as possible on application developers, enabling them to make as many decisions as possible about hardware abstractions. The design of the exokernel is very complex.


User mode vs Kernel mode


User mode: When the computer system starts an application program such as a photo editor then the system is in user mode. The transition between user mode to kernel mode happens when the application requests for a service from the operating system or an interrupt or a system call occurs.
By default, the mode bit is set to 1 in the user mode and it is changed from 1 to 0 while switching from user mode to kernel mode.

Kernel mode: Kernel mode is also called privileged mode or system mode. When the system boots, hardware starts in kernel mode and after the operating system is loaded it executes applications in user mode. In kernel mode, the processes get single memory address space.
When the process executes in user mode it requires hardware resources such as RAM, for that the process should send a request to the kernel and this request is sent through system calls and then the system enters kernel mode from user mode.
After the task is completed the kernel-mode changes back to user mode. This transition is called  “context switching”.
By default, the mode bit is set to 0 in the kernel mode and it is changed from 0 to 1 while switching from a kernel mode to user mode.

No comments:

Post a Comment

Featured Post

Managing user and groups, UID and GID in Linux

What are users in the operating system? A user is a person who accesses or utilizes computer resources or network services. In order to ...

Popular Posts