Table of Contents
A Linux kernel is a UNIX like operating system kernel. So obviously the kernel of Linux will be Unix like kernel. It is a computer program that is the core interface that connects the hardware components to the Software processes. So the software processes are those that we are trying to establish or trying to interpret. Normally we just type our command on shell and hit enter and we get a result. We don’t know what happens in the background. We discussed it in brief in a previous post on Linux shell. Let’s understand it once again.
So basically what happens is, whenever we type in the command on shell it is passed to the kernel which is in middle. A kernel is a very huge program. It could contain somewhere around or even more than 2 million lines of code. It is a very complicated and helpful program. The kernel is the main interconnection between the software application or the software processes and the hardware components.
So let’s say we are trying to find out how much RAM our system is using. We cannot directly go and check the RAM in our system. We instead use the process running in the background which connects to the hardware components and checks how much RAM is being used and then sends that information back to us. So this is what the kernel does.
There are basically top 4 operations performed by a Kernel are Resource Management, Memory Management, Device Management and System Call. Let us get a brief idea about each of these operations.
Resource Management and kernel
Kernel decides which process gets a resource for an operation. Let’s say you are running multiple processes and in those multiple processes two processes needs the same resource for an operation. In this case he decide which operation should use that resource first and which should use it second. This is because this same resource requirement by multiple processes should not end up in a deadlock situation.
To avoid this kernel performs an operation which basically chooses which process needs the resource right now or it may delay the process of execution. So it might give it to a process which takes lesser time first and then it gives resource to a process which takes longer time. So there are varieties of operation that can be performed in resource management.
Memory management is very important for any server or computer. Even if you are using a Windows system with 1 TB of space, then also memory management is very important. Memory management is taken care of by your system operating system in Windows. Similarly, Linux also takes care of memory management. The kernel has complete access to the system memory and must efficiently manage to allocate memory access to the process.
But why do we need memory? Memory is not for storing content. Memory is to run processes efficiently and effectively. So the kernel should know how much memory should be allocated to each process so that our system is not completely taken away of free memory. Let’s say we have 100 MB of memory and there are 10 processes. Then our system kernel should decide how much memory each process deserves to use, and it should allocate that much memory to the process efficiently.
Device management is pretty common in every single operating system. So if you are using a windows system and you enter a pen drive into USB port of your machine, you will be able to see that device in your computer. So like that, device management is also taken care by Kernel. If we connect devices such as printer or pen drive, the kernel will detect the device and the system will establish connection to the peripherals. So if I connect a pen drive then the Linux kernel will first detect it.
There is a separate directory in kernel which is knows as /dev. This particular directory is especially for device management in Linux operating system. Any device entering into any Linux operating system will have a separate directory for them in “/dev”. So if we enter pen drive into linux system then that pen drive will have a separate directory within the “/dev” directory from where we can access it.
System Calls is an interface between a process and the operating system. When the process does not have permissions to access a resource, a system call provides it without the process accessing the resource directly. So basically if we are running a process but we have not given the process enough permissions to use a particular resource. Then we can use system calls for that process by embedding system calls in our shell script or code so that when that particular system calls is used, their process will be given access to the resource indirectly. So the purpose of system calls is to make sure not to stop the process from running.
It does not interrupt our execution but it helps to complete execution as fast as possible. We also use system calls to do more operations at operating system level. There are various system calls that we can use. For example, we can use system call to abort a particular process immediately.
So these are the four important operations performed by Kernel. You must understand that Kernel is the main component of any Linux distribution. And the Kernel manages all of the top operations of a Linux distribution.