What is Kernel?
In computer science, Kernel is a computer program that is a core or heart of an operating system. Before discussing kernel in detail, let’s first understand its basic, i.e., Operating system in a computer.
Operating System
An operating system or OS is system software that works as an interface between hardware components and end-user. It enables other programs to run. Each computer system, whether it is desktop, laptop, tablet, or smartphone, all must have an OS to provide basic functionalities for the device. Some widely used operating systems are Windows, Linux, MacOS, Android, iOS, etc.
What is Kernel in Operating System?
- As discussed above, Kernel is the core part of an OS(Operating system); hence it has full control over everything in the system. Each operation of hardware and software is managed and administrated by the kernel.
- It acts as a bridge between applications and data processing done at the hardware level. It is the central component of an OS.
- It is the part of the OS that always resides in computer memory and enables the communication between software and hardware components.
- It is the computer program that first loaded on start-up the system (After the bootloader). Once it is loaded, it manages the remaining start-ups. It also manages memory, peripheral, and I/O requests from software. Moreover, it translates all I/O requests into data processing instructions for the CPU. It manages other tasks also such as memory management, task management, and disk management.
- A kernel is kept and usually loaded into separate memory space, known as protected Kernel space. It is protected from being accessed by application programs or less important parts of OS.
- Other application programs such as browser, word processor, audio & video player use separate memory space known as user-space.
- Due to these two separate spaces, user data and kernel data don’t interfere with each other and do not cause any instability and slowness.
Functions of a Kernel
A kernel of an OS is responsible for performing various functions and has control over the system. Some main responsibilities of Kernel are given below:
- Device Management
To perform various actions, processes require access to peripheral devices such as a mouse, keyboard, etc., that are connected to the computer. A kernel is responsible for controlling these devices using device drivers. Here, a device driver is a computer program that helps or enables the OS to communicate with any hardware device.
A kernel maintains a list of all the available devices, and this list may be already known, configured by the user, or detected by OS at runtime. - Memory Management
The kernel has full control for accessing the computer’s memory. Each process requires some memory to work, and the kernel enables the processes to safely access the memory. To allocate the memory, the first step is known as virtual addressing, which is done by paging or segmentation. Virtual addressing is a process of providing virtual address spaces to the processes. This prevents the application from crashing into each other. - Resource Management
One of the important functionalities of Kernel is to share the resources between various processes. It must share the resources in a way that each process uniformly accesses the resource.
The kernel also provides a way for synchronization and inter-process communication (IPC). It is responsible for context switching between processes. - Accessing Computer Resources
A kernel is responsible for accessing computer resources such as RAM and I/O devices. RAM or Random-Access Memory is used to contain both data and instructions. Each program needs to access the memory to execute and mostly wants more memory than the available. For such a case, Kernel plays its role and decides which memory each process will use and what to do if the required memory is not available.
The kernel also allocates the request from applications to use I/O devices such as keyboards, microphones, printers, etc.
Types of Kernel
There are mainly five types of Kernel, which are given below:
1. Monolithic Kernels
In a monolithic kernel, the same memory space is used to implement user services and kernel services.
It means, in this type of kernel, there is no different memory used for user services and kernel services.
As it uses the same memory space, the size of the kernel increases, increasing the overall size of the OS.
The execution of processes is also faster than other kernel types as it does not use separate user and kernel space.
Examples of Monolithic Kernels are Unix, Linux, Open VMS, XTS-400, etc.
Advantages:
- The execution of processes is also faster as there is no separate user space and kernel space and less software involved.
- As it is a single piece of software hence, it’s both sources and compiled forms are smaller.
Disadvantages:
- If any service generates any error, it may crash down the whole system.
- These kernels are not portable, which means for each new architecture, they must be rewritten.
- Large in size and hence become difficult to manage.
- To add a new service, the complete operating system needs to be modified.
2. Microkernel
A microkernel is also referred to as μK, and it is different from a traditional kernel or Monolithic Kernel. In this, user services and kernel services are implemented into two different address spaces: user space and kernel space. Since it uses different spaces for both the services, so, the size of the microkernel is decreased, and which also reduces the size of the OS.
Microkernels are easier to manage and maintain as compared to monolithic kernels. Still, if there will be a greater number of system calls and context switching, then it might reduce the performance of the system by making it slow.
These kernels use a message passing system for handling the request from one server to another server.
Only some essential services are provided by microkernels, such as defining memory address spaces, IPC(Interprocess Communication), and process management. Other services such as networking are not provided by Kernel and handled by a user-space program known as servers.
One of the main disadvantages of monolithic kernels that an error in the kernel can crash the whole system, can be removed in the microkernel. As in a microkernel, if a kernel process crashes, the crashing of the whole system can still be prevented by restarting the error-caused services.
Examples of Microkernel are L4, AmigaOS, Minix, K42, etc.
Advantages
- Microkernels can be managed easily.
- A new service can be easily added without modifying the whole OS.
- In a microkernel, if a kernel process crashes, it is still possible to prevent the whole system from crashing.
Disadvantages
- There is more requirement of software for interfacing, which reduces the system performance.
- Process management is very complicated.
- The messaging bugs are difficult to fix.
3. Hybrid Kernel
Hybrid kernels are also known as modular kernels, and it is the combination of both Monolithic and Microkernels. It takes advantage of the speed of monolithic kernels and the modularity of microkernels.
A hybrid kernel can be understood as the extended version of a microkernel with additional properties of a monolithic kernel. These kernels are widely used in commercial OS, such as different versions of MS Windows.
It is much similar to a microkernel, but it also includes some additional code in kernel space to enhance the performance of the system.
Hybrid kernels allow to run some services such as network stack in kernel space to reduce the performance compared to a traditional microkernel, but it still allows to run kernel code (such as device drivers) as servers in user-space.
Examples of Hybrid Kernel are Windows NT, Netware, BeOS, etc.
Advantages:
- There is no requirement for a reboot for testing.
- Third-party technology can be integrated rapidly.
Disadvantages:
- There is a possibility of more bugs with more interfaces to pass through.
- It can be a confusing task to maintain the modules for some administrators, especially when dealing with issues such as symbol differences.
4. Nanokernel
As the name suggests, in Nanokernel, the complete code of the kernel is very small, which means the code executing in the privileged mode of the hardware is very small. Here the term nano defines a kernel that supports a nanosecond clock resolution.
Examples of Nanokernel are EROS etc.
Advantages
- It provides hardware abstractions even with a very small size.
Disadvantages
- Nanokernel lacks system services.
5. Exokernel
Exokernel is still developing and is the experimental approach for designing OS.
This type of kernel is different from other kernels as in this; resource protection is kept separated from management, which allows us to perform application-specific customization.
Advantages:
- The exokernel-based system can incorporate multiple library operating systems. Each library exports a different API, such as one can be used for high-level UI development, and the other can be used for real-time control.
Disadvantages:
- The design of the exokernel is very complex.
What is Kernel Panics?
As we have already discussed, that kernel controls over entire computer system; hence if it crashes, it can take down the whole system. In MacOS and Linux, such an undesirable event is known as “Kernel Panic.” To recover from kernel Panic, we need to restart the system.
Usually, these kernel panics are caused by hardware communication issues. Hence, if repeated kernel panics are occurring, then try to unplug the less required or unnecessary devices and check if the problem is get resolved or not.