You are on page 1of 53

KERNEL

in Operating Systems
Objectives
 Kernel
 History of kernel
 Functions of kernel
 Types of kernel
 Kernel mode and user mode
 Errors
 Kernel panic
 Fatel error
 BSOD (blue screen of death)
Kernel
 The “Kernel” is nothing but the core component of an OS (Operating System). This kernel
directly deals with hardware part of computers and acts as a bridge between applications and
the data processing unit which performs at the hardware level. Also, it is
responsible for basic tasks like Disk management, memory management, and task
management.

 As the “kernel” is the core of operating system it provides the basic services to other parts of
OS and it has the complete control over everything that happens in the system. During
system booting or system startup, it is the first part of the operating system which loads into
the memory. Due to the critical nature of kernel, it’s loaded in the protected area of
memory.

Software Kernel Hardware


 Kernel the lowest layer above the cpu.

APP

System Resources

Kernel

Hardware
History of kernel
To learn about how Linux came to be, let’s go back to the beginning to 1969 where Ken Thompson and Dennis
Ritchie of Bell Laboratories developed the UNIX operating system. It was later rewritten in C to make it more
portable and eventually became a widely used operating system.
A decade or so later, Richard Stallman started working on the GNU (GNU is Not UNIX) project, the GNU kernel
called Hurd, which unfortunately never came to completion. The GNU General Public License (GPL), a free software
license, was also created as a result of this.
The kernel is the most important piece in the operating system. It allows the hardware to talk to the software. It
also does a whole lot of other things, but we’ll dig into that in a different course. For now, just know that the kernel
controls pretty much everything that happens on your system.
During this time other efforts such as BSD, MINIX, etc were developed to be UNIX like-systems. However, one
thing that all these UNIX like-systems had in common was the lack of a unified kernel.
Then in 1991, a young fellow named Linus Torvalds started developing what we now know today as the Linux kernel.
Debate(Linus Torlvard and Andrew S. Tanenbaum)
The Tanenbaum–Torvalds debate was a written debate between Andrew S. Tanenbaum and Linus Torvalds,
regarding the Linux kernel and kernel architecture in general. Tanenbaum, the creator of Minix, began the
debate in 1992 on the Usenet discussion group comp.
https://www.oreilly.com/openbook/opensources/book/appa.html

 According to linus tolvard


monolithic kernel is more
better then micro kernel
that’s why he is using
monolithic structure in
linux.
First version of kernel
version 0.01
In September 1991, Linus released the first version of the Linux kernel on the File Transfer Protocol (FTP)
server of the Finnish University and Research Network (FUNET). This version was called version 0.01 and
contained 10,239 lines of code.
Latest kernel version
the latest stable kernel version of the Linux operating system was version 5.14. At the time of this
response on March 13, 2023, the latest stable kernel version is 5.16, although newer versions may have
been released by the time you read this.
the Linux kernel is open source software. The source code for the Linux kernel is available for anyone to
view, modify, and distribute under the terms of the GNU General Public License. This means that anyone can
download the source code, modify it, and distribute their modified version as long as they also make the
source code for their modified version available to others.
How to check the kernel version?
Linux
The command “uname -r” shows the version of the Linux kernel that you're currently using. You'll now
see which Linux kernel you're using.
Windows
To determine the kernel version, use a registry editor (e.g., regedit.exe) to view the CurrentVersion
registry value at the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\
CurrentVersion subkey.
The kernel file itself is ntoskrnl.exe . It is located in C:\Windows\System32 . If you view the
properties of the file, you can look on the Details tab to see the true version number running.
Android
icon on your Apps menu to open Settings. Scroll down and tap About. This option will open your Android's
software and hardware details. Depending on your device and software version, this option may also be named
About device, About phone, or About tablet.
 Functions of Kernel
 Process management
 Access computer resources
 Device management
 Memory management
 Interrupt handling
 I/O communication
 File system...etc.
 Access Computer resource
A Kernel can access various computer resources like the CPU, I/O devices and other
resources. It acts as a bridge between the user and the resources of the system.
 Resource Management
It is the duty of a Kernel to share the resources between various process in such a way
that there is uniform access to the resources by every process.
 Memory Management
Every process needs some memory space. So, memory must be allocated and
deallocated for its execution. All these memory management is done by a Kernel.
 Device Management 
The peripheral devices connected in the system are used by the processes. So, the
allocation of these devices is managed by the Kernel.
 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.
 Types of Kernel

 Monolithic Kernels
 Microkernel
 Hybrid Kernel
 Nanokernel
 Exokernel
 Monolithic Kernel
Monolithic Kernels are those Kernels where the user services and the kernel services are
implemented in the same memory space i.e. different memory for user services and kernel services are not
used in this case. By doing so, the size of the Kernel is increased and this, in turn, increases the size of the
Operating System. As there is no separate User Space and Kernel Space, so the execution of the process
will be faster in Monolithic Kernels
Example
Unix, Linux, Open VMS, XTS-400 etc.
 Advantages
It provides CPU scheduling, memory scheduling, file management through System calls only.
Execution of the process is fast because there is no separate memory space for user and kernel.
 Disadvantages
If any service fails, then it leads to system failure.
If new services are to be added then the entire Operating System needs to be modified.
 Microkernel
A Microkernel is different from Monolithic kernel because in a Microkernel, the user services and
kernel services are implemented into different spaces i.e. we use User Space and Kernel Space in case of
Microkernels. As we are using User Space and Kernel Space separately, so it reduces the size of the
Kernel and this, in turn, reduces the size of Operating System.
As we are using different spaces for user services and kernel service, so the communication between
application and services is done with the help of message parsing and this, in turn, reduces the speed of
execution.
Example
Mach, L4, AmigaOS, Minix, K42 etc.
 Advantages
If new services are to be added then it can be easily added.
 Disadvantages
Since we are using User Space and Kernel Space separately, so the communication between these can
reduce the overall execution time.
 Hybrid Kernel
A Hybrid Kernel is a combination of both Monolithic Kernel and Microkernel. It makes the use of
the speed of Monolithic Kernel and the modularity of Microkernel.
Hybrid kernels are micro kernels that have some "non-essential" code in kernel-space in order for the
code to run more quickly than it would be in user-space. So, some services such as network stack or
filesystem are run in Kernel space to reduce the performance overhead, but still, it runs kernel code
as servers in the user-space.
Example
Windows NT, Netware, BeOS etc.
 Nanokernel
In a Nanokrnel, as the name suggests, the whole code of the kernel is very small i.e. the code
executing in the privileged mode of the hardware is very small. The term nanokernel is used to
describe a kernel that supports a nanosecond clock resolution.
Example
EROS etc.
 Exokernel
Exokernel is an Operating System kernel that is developed by the MIT parallel and the Distributed
Operating Systems group. Here in this type of kernel, the resource protection is separated from the
management and this, in turn, results in allowing us to perform application-specific customization.
In the Exokernel, the idea is not to implement all the abstractions. But the idea is to impose as few
abstractions as possible and by doing so the abstraction should be used only when needed. So, no
force abstraction will be there in Exokernel and this is the feature that makes it different from a
Monolithic Kernel and Microkernel. But the drawback of this is the complex design. The design of the
Exokernel is very complex.
Example
Nemesis, ExOS etc.  Exokernel is an operating system developed
at the MIT that provides application-level
management of hardware resources. This
architecture is designed to separate
resource protection from management to
facilitate application-specific
customization.
There are two modes of operation in the operating system to make sure it works correctly. These are user mode and
kernel mode.
As follows:
 Kernel Mode and User Mode
There are certain instructions that need to be executed by Kernel only. So, the CPU executes these
instructions in the Kernel Mode only. For example, memory management should be done in Kernel-Mode
only. While in the User Mode, the CPU executes the processes that are given by the user in the User
Space.
 User Mode
The system is in user mode when the operating system is running a user application such as handling a text
editor. The transition from user mode to kernel mode occurs when the application requests the help of operating
system or an interrupt or a system call occurs.
The mode bit is set to 1 in the user mode. It is changed from 1 to 0 when switching from user mode to kernel mode.
 Kernel Mode
The system starts in kernel mode when it boots and after the operating system is loaded, it executes
applications in user mode. There are some privileged instructions that can only be executed in kernel
mode.
These are interrupt instructions, input output management etc. If the privileged instructions are
executed in user mode, it is illegal and a trap is generated.
The mode bit is set to 0 in the kernel mode. It is changed from 0 to 1 when switching from kernel mode
to user mode.
An image that illustrates the transition from user mode to kernel mode and back again is −
User Mode mode bit=1

User Process Gets System Return From


Executing Call System Call

trap trap
mode bit=0 mode bit=1

Execute System
Call

Kernel Mode mode bit=0


In the above image, the user process executes in the user mode until it gets a system call. Then a system trap is
generated and the mode bit is set to zero. The system call gets executed in kernel mode. After the execution is
completed, again a system trap is generated and the mode bit is set to 1. The system control returns to kernel mode
and the process execution continues.

 Necessity of Dual Mode (User Mode and Kernel Mode) in Operating System
The lack of a dual mode i.e user mode and kernel mode in an operating system can cause serious problems.
Some of these are −
 A running user program can accidentaly wipe out the operating system by overwriting it with user data.
 Multiple processes can write in the same system at the same time, with disastrous results.
 Booting and Dual Booting of Operating System
After an operating system is generated, it must be available for the use by the hardware.
But how the hardware know where the kernel is, or how to load that kernel? The procedure of
starting a computer by loading the kernel is known as Booting the system. Hence it needs a
special program, stored in ROM to do this job known as the Bootstrap loader. Example: BIOS
(boot input output system). A modern PC BIOS (Basic Input/Output System) supports booting
from various devices. Typically, the BIOS will allow the user to configure a boot order. If the
boot order is set to:
 CD Drive
 Hard Disk Drive
 Network
Then the BIOS will try to boot from the CD drive first, and if that fails then it will try to boot from the hard
disk drive, and if that fails then it will try to boot from the network, and if that fails then it won’t boot at all.
Booting is a startup sequence that starts the operating system of a computer when it is turned on. A boot
sequence is the initial set of operations that the computer performs when it is switched on. Every computer
has a boot sequence. Bootstrap loader locates the kernel, loads it into main memory and starts its execution.
In some systems, a simple bootstrap loader fetches a more complex boot program from disk, which in turn
loads the kernel. 

power on computer

BIOS performs post

DISK RAM
Loading of os
 Kernel panic
Kernel panic is the action taken by an operating system kernel when it encounters a fatal error from which it
can't safely recover. The term is usually used in reference to Unix and Unix-like operating systems such as 
Linux and BSD. It is similar to the condition of Windows operating systems known as the blue screen of death.
When an operating system panics, it displays an error message on the screen, and writes the contents of
kernel memory (a core dump) to disk for later debugging. It then halts all CPU operation. It then either reboots
 automatically or waits for the user to manually reboot the machine, depending on how the operating system is
configured.
A kernel panic is different than a system crash. With a crash, the kernel detects an abnormal condition, and
forcefully terminates software execution. It does so to minimize the likelihood of data loss or another corruption
of the state of the machine. However, in a kernel panic, the kernel itself terminates abnormally.
In layman's terms, a kernel panic is simply a safety measure taken by an operating system to lower the risk
of hardware damage. For example, when your device has a major system error, the kernel sends a signal to
shut down the device and then shows error codes that tell you what exactly happened.
BSoD (Blue Screen of Death)
Alternatively called a bluescreen or bugcheck in Microsoft Windows NT, 2000, and XP, BSoD is short for Blue
Screen of Death and is a full blue screen Windows error message.
The blue screen is most commonly encountered and associated with a computer running Microsoft Windows.
However, other operating systems, such as macOS, may also get a blank blue screen, which is also called a
BSoD. A blank blue screen on Apple computers indicates that the hard drive in the computer is bad.
Fatal Error
A fatal error is an error that causes a program to terminate without any warning or saving its state. A fatal
error, upon occurring, aborts the application currently running, and may cause the user to lose any unsaved
changes made in the program. Exact reasons for fatal errors are very difficult to determine.
A fatal error is also known as a fatal exception error.
What Causes a Fatal Error?
When you run a program on an operating system like Windows, and the program encounters something
unexpected, it generates a message called an exception. These exceptions allow programs to run smoothly
and operate normally, even when something unexpected happens.
When a program is given or generates an unknown or unexpected exception, the result is a fatal error. This
same type of problem can also be referred to as a fatal exception, or a fatal exception error.
Depending on the severity of the error, you may be given the option to continue running the program, or the
program may terminate automatically.
How Fatal Errors Appear
Fatal error messages typically appear when a program suddenly shuts down because of some type of
failure, or when a Windows computer suddenly displays the blue screen of death before shutting down, or
when a macOS or Linux computer suffers a kernel panic.
Linux
On Linux computers, there is also a concept known as kernel oops, which refers to a serious error
that the operating system isn't capable of handling. The system will continue to run, but it may cause
instability and may even result in a full kernel panic, manifested by a black screen filled with code.

Android
Kernel panics also occur on Android OS. However, due to kernel optimizations and Android security
updates, it is less probable that the newer versions of Android would experience a Kernel Panic. In
general, it all depends on the operating system's optimizations, the hardware, and other such factors. So
the recommendation is to update to the latest Android version.
What to Do When You Get One
When you encounter a kernel panic or BSOD, the only thing you can do is restart your computer and
resume your work.
The kernel panic generates a log file with information that can assist an engineer in deciphering what
occurred. You should be offered the opportunity to send this to the OS developer upon restarting,
depending on your operating system.
It's important to remember that a kernel panic is only a sign that an error occurred, not that there's
anything fundamentally wrong with your PC. Everyone will get them from time to time, and you can happily
forget about it.
Troubleshooting a Kernel Panic
Each time a kernel panic occurs, a log containing information about what happened will be created. It's
mostly incomprehensible to the regular user, although a scan of the data can sometimes reveal a particular
app that was at fault.
On Windows, you may need to download and install the Debugging Tool for Windows to examine the
log. Mostly, though, you'll just need to investigate some common causes to see if they are to blame.
Hardware Issues
When looking for possible causes of your kernel panics, the key is to try and identify any changes you've
made to your system recently.
Undoing these changes and then re-enabling them one at a time helps you isolate a possible cause.
Check the RAM:
If you have upgraded the RAM in your computer, the first step is to check that it is seated properly. If the
problem persists, remove the RAM you added. If that solves it, the RAM may be faulty, so contact your
retailer for an exchange.
Detach Peripherals:
It isn't just large add-ons like scanners and printers that can cause potential problems. A kernel
panic can be caused by something as benign as a USB flash drive. Once you are confident that a
particular device isn't at fault, you can reconnect it.
Check for Disk Errors:
Run the disk repair software built into your computer's operating system to ensure that disk
errors are not causing your kernel panics. If the computer crashes as soon as it boots, you will
need to either boot into the Recovery partition (usually F10 on Windows and Command + R on
Mac; for Linux, it depends on the distro being used) or boot from a disk or USB drive to carry out
these diagnostic tasks.
Software Issues
If the software is the cause of your kernel panic (or Blue Screen of Death), you will tend to pick up
which program it is over a period. Sometimes, though, applications running in the background, such as
security software, may be the cause.
To diagnose software problems, boot into Safe Mode on Mac or Windows. Safe mode loads only the
core elements of the operating system. Do this on Windows by holding F8 when you restart, and on Mac,
you hold the Shift key after you hear the startup chime. Linux doesn't have a safe mode as such, only a
recovery partition.
Check Software and Startup Items:
Check all your software is up-to-date, and also look at which programs are launching on boot.
Disable any that you installed shortly before you started to experience kernel panics, then re-enable them
in turn.
Update the System:
Download and install the latest updates for your operating system, as well as drivers for your hardware
on Windows. If you're testing beta or preview versions of your operating system, these may not be stable,
so they could be the cause of the problem.
Use System Restore:
If you make a lot of changes to your system, consider using System Restore or Time Machine to roll
back to a time before the kernel panics occurred.
Reinstall your OS:
If none of the above worked, you can try a method that will almost certainly save your desktop or
laptop -reinstall your operating system from scratch. It's similar to beginning a new life - and it's not tough
at all.
MCQ’s
1.What is the role of the kernel in an operating system?
A. To manage system resources
B. To provide user interface
C. To run user applications
D. To store user data

2.What is the difference between monolithic and microkernel architectures?


A. Monolithic kernels are smaller than microkernels
B. Monolithic kernels are faster than microkernels
C. Monolithic kernels include all operating system functions, while microkernels only include
essential functions
D. Microkernels include all operating system functions, while monolithic kernels only include essential
functions
3.How does the kernel provide memory management?
A. By allocating memory to user applications
B. By freeing memory used by user applications
C. By providing virtual memory and memory protection
D. By managing disk space

4.What is process scheduling in the kernel?


A. The process of allocating memory to user applications
B. The process of managing user input/output operations
C. The process of managing and prioritizing user applications that require CPU time
D. The process of managing device drivers
5.What is the role of device drivers in the kernel?
A. To manage memory allocation
B. To manage user input/output operations
C. To manage network connections
D. To manage communication with hardware devices

6.Which kernel architecture is more modular and easier to maintain?


A. Monolithic kernel
B. Microkernel
C. Hybrid kernel
D. None of the above
7.Which technique is used by the kernel to manage virtual memory?
A. Paging
B. Swapping
C. Both a and b
D. None of the above

8.What is the purpose of device drivers in an operating system?


E. To provide low-level services to applications
F. To enable the operating system to communicate with hardware devices
G. To manage system memory for running processes
H. None of the above
9.Which component of an operating system is responsible for allocating physical memory to running
processes?
A. Kernel
B. Device driver
C. File system
D. None of the above

10.Which kernel architecture has all kernel services integrated into a single kernel image?
E. Monolithic kernel
F. Microkernel
G. Hybrid kernel
H. None of the above
 Possible short questions.
 What is the kernel in an operating system?
 What are the main functions of a kernel?
 What is the difference between a monolithic and microkernel architecture?
 How does a kernel provide memory management?
 What is process scheduling in the kernel?
 How does the kernel handle input/output operations?
 What is the role of device drivers in the kernel?
 What is virtualization, and how does it relate to the kernel?
 What are system calls, and how do they interact with the kernel?
 How does the kernel provide security and protect against unauthorized access?
 How does the kernel manage and allocate system resources such as CPU time and memory?
 What is kernel panic, and how does the kernel handle it?
 What is the role of interrupts in the kernel, and how are they handled?
 What is a context switch, and how does the kernel perform it?
 How does the kernel handle file systems and disk management?
 Possible long Questions
 Explain the role of the kernel in an operating system.
 What is a system call, and how does the kernel handle system calls?
 What is the difference between a monolithic kernel and a microkernel?
 How does the kernel manage memory in an operating system?
 What is the boot process, and how does the kernel boot an operating system?

You might also like