What is kernel in operating system

The Kernel is the heart of an operating system. It is the kernel of an OS through the medium of which the OS exercises control over the computer system.

When a system boots up, the Kernel is the first program that is loaded in memory after the bootloader because the kernel handles the rest of the functions of the system for the OS. The Kernel remains in the memory until the OS shuts down.

The kernel provides a part of the time to each process, when a process has finished executions the kernel starts another process, determines the state of the process, which could be one of running, waiting, or ended.

2. Resource Allocation:

The kernel controls memory, peripheral devices, and CPU processes. It also acts as link between resources and processes. It allocates the memory to the processes. If any process requires access to some hardware component, the kernel allocates that component to it.

3. Device Management:

The kernel manages the devices connected with the system, such as I/O devices, storage devices, etc and also the exchange of data through these devices. The information is received from the system and transferred to it from the I/O devices and various applications.

4. Interrupt Handling and System Calls:

When a process runs, there may arise a task of high priority that needs to be executed first. The kernel switches the control from the currently running process to the new one as per their priorities. The kernel also deals with system calls, which simply put are software interrupts.

5. Memory Management:

Once the kernel creates and executes a process, it lives in memory having occupied space in it. When the process ends, the kernel removes the process from the memory. Kernel assigns the memory to process and releases it as well.

6. Process Management:

The kernel performs the creation, execution, and ending of processes that run in the system. When a system has to execute any task, the kernel creates and manages the processes.

Kernels are of following 5 types:

1. Monolithic Kernel:

Monolithic Kernel implements fundamental features of a computer system such as managing files, memory, and other resources. It gives the OS a primitive architecture in which all the resources are associated with kernel-space. Some examples of operating systems that use monolithic kernels are Dos, Solaris, AIX, Linux, OpenVMS, etc.

A monolithic kernel suits minute tasks such as CPU scheduling, system calls, etc. This is so because it manages limited resources. But, owing to its features such as reliability, security, and speed of access, many financial projects utilize operating systems that use monolithic kernels.

All the hardware controlling software components needed for processing are embedded within the kernel and can therefore also communicate with each other directly and also with the kernel. A monolithic kernel can load modules dynamically which incurs a very small overhead as contrary to building the module into the OS image.

Advantages

  • A monolithic kernel is fast because services like memory management, file management, etc are implemented in the same address space.
  • A process runs entirely in single address space in monolithic kernels.
  • A monolithic kernel is a single static file.
  • Few bugs and security problems are also less.
  • System calls are used to do operations in monolithic kernels.
  • Execution of the process is fast due to separate memory space for user and kernels.

Disadvantages

  • If any service fails, then the entire system fails too.
  • If any new features are added then the issue is to modify the complete system.
  • Coding and debugging in the kernel space is difficult.
  • Bugs in one part of kernel space produce strong effects in other parts also.
  • These Kernels are huge and difficult to maintain and not always portable.

2. Microkernel Kernels

A microkernel is the type of operating system architecture that is useful in the same way as the other architectures are and is used for file management, memory management, and the scheduling of the processes.

A microkernel is similar to a monolithic kernel but it additionally has some space allotted for several other purposes such as file sharing, scheduling, kernel services, etc.

Each of these services has its address allotted which results in the reduction of the size of the kernel and consequently the entire OS.

The fundamental of a microkernel is to attain high reliability by breaking the OS into smaller, well-defined modules. A microkernel provides a communication facility between the client program and many services that run in userspace.

All new services are added to the user space and the kernel needs not be modified. The microkernel provides high security as most of the services run in user space; if a service fails the rest of the OS remains intact.

Advantages

  • Microkernels are secure as only those parts which might influence the system's functionality are added.
  • The various modules of a microkernel can be swapped, reloaded, and modified without affecting the kernel.
  • A microkernel architecture is compact and isolated, so it performs better.
  • Due to the modular structure of microkernels, they have fewer system crashes and are simply handled.
  • New functionality can be added to a microkernel without having to recompile it later.

Disadvantages

  • When the drivers are implemented as procedures, a context switch or a function call is needed.
  • In a microkernel-based OS, providing services is costlier in comparison to a monolithic system.
  • The performance of a microkernel system might stay uniform and cause issues.

3. Hybrid Kernels

Hybrid kernels combine aspects of monolithic and microkernel architectures. They're an extension of the concept of a microkernel with additional code in kernel space and some monolithic kernel attributes to enhance the performance. Hybrid kernels can't load modules at runtime. XNU (abbreviation for "X Is Not Unix") is a hybrid kernel that contributed to the development of MacOS, IOS, WatchOS, and tvOS operating systems.

Unlike the case of a microkernel where everything occurs in user-level servers and drivers, the designer of a hybrid kernel could decide to keep several components inside the kernel and others outside. This benefits performance, simplicity, and vendor lock-in. The development of hybrid kernels starts as monolithic kernels and begins moving components into user-land.

Advantages

  • A hybrid kernel is easy to manage due to its layered approach.
  • Number of layers is not very high generally.
  • Kernel is small in size and isolated.
  • Provides better security and protection.

Disadvantages

  • Since a hybrid kernel strikes a balance between the gains in monolithic kernel and microkernel, there are certain benefits of both that are lost out or compromised.

4. Nano Kernel

It's a kernel in which the total amount of kernel code is tiny. It includes the code that executes in the hardware's privileged mode. The term nanokernel can be described as a kernel that supports clock resolution of a nanosecond.

For an instance, KeyKOS is a capability-based, object-oriented OS. It's been around since 1983. It is based on nanokernel architecture. It addresses requirements such as reliability, security, and consistent availability for software and applications. The motivation behind creation of this OS was to be able to run many instances of several operating systems on one system. The KeyKOS nanokernel can run within just 100KB of memory and is roughly twenty thousand lines of code in C programming language.

Advantages

  • The source code is very small and binaries likewise.
  • Very efficient in terms of performance.

Disadvantages

  • Does not include a lot of features directly incorporated.
  • It is less in use because of it's being similar to microkernels.

5. Exokernels

An exokernel operating system aims to provide application-level management of hardware resources. The architecture given is designed to isolate the resource protection from management and facilitate application-specific customization.

If we look at the general architecture of operating systems, the hardware resources are presented to applications through high levels of abstraction. This is done to relax the complexity of the underlying hardware. Therefore, this structure has a great effect on the performance of the applications and the types of supported applications that can be built on this OS.

The main idea behind Exokernels is to reduce the level of abstractions provided by operating systems and to allow application-level management of hardware resources as much as possible. This gives the power to application developers to declare their levels of abstractions and manage the hardware.

Advantages

  • Better Support for Application Control.
  • Separates Security from Management.
  • Abstractions are moved securely to an untrusted "Library Operating System".
  • Provides a low-level interface.
  • Library operating systems offer Portability and Compatibility.

Disadvantages

  • When it comes to application/OS development, each developer will develop them the way they see fit. Due to this reason, the level of consistency will be a bit reduced.
  • Design of the interface in an exokernel is complicated.