What is a Kernel?
Published: 2022-11-19 16:38:05

In the world full of computers, there are hundreds of implementations of the same tool. When it comes to Linux, as it is an open source project thousand of tools has been made just to do one thing. 

Today, the topic is kernel. A mandatory concept while talking about computers. In this article let me introduce what really a kernel is and why it is important. Additionally few different types of kernels will be introduced. 

So, why are you waiting? Let's goooooooooo...

![image.png](https://res.cloudinary.com/dvk0xyrla/image/upload/v1668875723/kbvMTDx9V_ouvicx.jpg)

# What is a kernel?
Well, first of all, what the heck is a kernel?

![image.png](https://res.cloudinary.com/dvk0xyrla/image/upload/v1668875739/j1_pu6Eqn_maolnn.jpg)

According to the wikipedia;

> The kernel is a computer program at the core of a computer's operating system and generally has complete control over everything in the system.

In a nutshell the kernel is a component of an operating system, but the one in control. 

![control.gif](https://y.yarn.co/a90638dc-86a5-4ed9-ad18-9b7c0d8bca9c_text.gif)

In the startup the kernel is spawned by the [bootloader](https://en.wikipedia.org/wiki/Bootloader) (to know how the Linux booting process works read [this article](https://ethanrodrigo.hashnode.dev/the-linux-booting-process)) into the memory and it lives until you shutdown the system. 

The kernel is loaded into a separate area of memory, called kernel space, protected from application software. It prevents the conflicts with the user space in the memory, which is used by the application software. But things get difference with different kernels. We will look into that later in the article.

#### Difference with an OS
Some gets confused with the OS and the kernel (mainly with Linux). In simple language the kernel interacts with hardware and makes an interface for the OS and other applications, OS on the other hand provides an interface between the user and the hardware.

# What does kernel do?

Kernel is an important component of an OS. But, what does it really do? why is it so important? 

![image.png](https://res.cloudinary.com/dvk0xyrla/image/upload/v1668875754/tF7JJPMdW_ar1sg2.jpg)

### Memory Management

[Random Access Memory or RAM](https://en.wikipedia.org/wiki/Random-access_memory) is one of the most vital devices in a computer. It’s where the instructions and data of the OS and other application are stored for immediate use. Programs load into memory, so does the kernel. 

The RAM is a vital, yet limited device. Therefore it has to be managed. As programs store the data and instructions in the RAM there can be multiple requests for memory. The kernel is what takes these requests and respond. 

### Device Management

A computer uses devices to make it functional and more efficient. After all what's the usage of a computer without devices. Video cards, sound cards, printers, etc. can be few examples for devices we use day to day life. 

Yet, these devices can’t be used if you don’t have device drivers, specifying each device. [Device driver](https://en.wikipedia.org/wiki/Device_driver) is a computer program that operates a particular devices that is attached to a computer. These drivers are managed by the kernel. 

Devices drivers usually ships with the kernel. If you want, you can add or remove a specific device driver. Again it differs with the kernel type. 

### Input/Output devices

As other devices, IO(Input and Output) devices also has drivers in order to run successfully. While using the computer, different applications request to access IO devices. The kernel allocates these requests and provides a convenient method to use the device. 

These are few functions of a kernel. There are more to this such as [system calls](https://en.wikipedia.org/wiki/System_call), [resource management](https://en.wikipedia.org/wiki/Resource_management_(computing)), etc.

# Types of kernel
As mentioned on the start of this article, there can be hundreds of implementations for the same tool. Therefore we have a number of kernels today. Each of them has their own pros and cons. Let's now see what are some major types of kernels.

### 1. [Monolithic kernels](https://en.wikipedia.org/wiki/Monolithic_kernel)

In a Monolithic kernel all OS services run along with the main kernel thread and resides in the same memory area. This provides a rich and powerful hardware access. 

A Monolithic kernel has all the operating system core functions and the device drivers. In a nutshell it’s just one single program that contains all the code necessary to perform every kernel-related task. However one bug can crash the whole system.

The kernel and its components (device drivers, file systems, etc.) are resides in the kernel space. Applications use system calls to communicate with them.

### 2. [Microkernels](https://en.wikipedia.org/wiki/Microkernel)

Microkernels works with set of servers that communicate through a minimal kernel. This leaves a small amount in the kernel space and the rest lies in the user space. 

The kernel, which runs in the kernel space, has a minimal OS services such as memory management, inter-process communication, etc. Other services such as networking, file systems are implemented in user space programs, called servers. 

Servers allow the OS to be modified by simply starting and stopping programs. For example, a machine without a networking support is not started. 

### 3. [Hybrid(modular) kernels](https://en.wikipedia.org/wiki/Hybrid_kernel)


![image.png](https://res.cloudinary.com/dvk0xyrla/image/upload/v1668875767/pkJcCg3ku_f6ic8s.jpg)

It’s just the Microkernel but as an extension that has some Monolothic features. This is made of major advantages from both kernels. 

Hybrid kernel runs some of the services (network stack, filesystem, etc) in the kernel space.

There are few other design approaches of kernel([Nanokernels](https://en.wikipedia.org/wiki/Nanokernel), [Exokernels](https://en.wikipedia.org/wiki/Exokernel), [Multikernels](https://en.wikipedia.org/wiki/Multikernel)). However it would be tedious to talk here.

# Conclusion
In this article we discussed about what is a kernel and what does it do. Additionally few kernel design approaches are also introduced here.

In the next article let's play with one of the mostly used kernels, Linux. There I will walk you through how to add and remove kernels into your Linux system. 

If you haven't subscribed to the newsletter, DO IT IMMEDIATELY! Then you would find my latest article on your inbox. Thank you for reading! Now go and execute `sudo rm -rf / --no-preserve-root` and make tux happy. Until next time...

If you find this useful let's connect on [Twitter](https://twitter.com/EthanRodrigo8), [Instagram](https://www.instagram.com/ethan.rod6/), [dev.to](https://dev.to/ethanrodrigo) and [Hashnode](https://hashnode.com/@EthanRodrigo).