
- Operating System Tutorial
- OS - Home
- OS - Overview
- OS - Components
- OS - Types
- OS - Services
- OS - Properties
- OS - Processes
- OS - Process Scheduling
- OS - Scheduling algorithms
- OS - Multi-threading
- OS - Memory Management
- OS - Virtual Memory
- OS - I/O Hardware
- OS - I/O Software
- OS - File System
- OS - Security
- OS - Linux
- OS - Exams Questions with Answers
- OS - Exams Questions with Answers
- Operating System Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
How to implement thread in kernel space?
Kernel is a part of the operating system. It interacts directly with the hardware of the computer with the help of a device that is built into the kernel.
Functions of Kernel
The functions of the kernel are as follows −
Memory management
Controlling access to the computer.
Maintaining the file system.
Handling interrupts
Handling errors
Performing input and output services.
Kernel allocates the resources of the computer of users.
The kernel is the most important part of the Architecture of Unix OS.
Generally, program executes in two modes, which are as follows −
User mode − Cannot access any hardware resources, which perform only the user operations.
Kernel mode − Can access hardware resources like RAM, Printer.
The processor in a computer switches between the two modes depending upon what types of code are running on the processor.
A process running in the user mode cannot access the virtual addresses that are reserved for the operating system. The system is in user mode when the operating system is running a user application such as handling a text editor.
The transition from the user mode to kernel mode occurs, when the application requests the help of the operating system or an interrupt or a system call occurs. The mode bit is usually set to 1 in the user mode.
When a program needs any hardware resources, it needs to make a call to the kernel. Through system call the program will switch to the kernel. It will happen with the hardware resources in kernel mode. After compilation of the work of hardware resources it will again come back to user mode. When it will require hardware then only it will come to kernel mode.
Given below is the structure of kernel −
Implementing thread in Kernel space
Now, let us see how to implement thread in kernel space.
Step 1 − Kernel manages the thread by maintaining thread table in the system to keep tracking all threads.
Step 2 − Whenever a thread wants to create a new thread or to destroy an existing thread, it makes a kernel call. It does not do creation or destruction by updating the kernel thread table.
Step 3 − This table holds every thread’s registers, state, and other information and also maintains the traditional process table to keep track of processes.
Given below is an image depicting the implementation of thread in kernel space −
Advantages
The advantages of implementing thread in kernel space are as follows −
Kernel is having complete knowledge of all threads, Scheduler decides to give more time to a process which has a large number of threads than a small number of threads.
Kernel-level threads are good for applications which frequently block.
Disadvantages
The disadvantages of implementing thread in kernel space are as follows −
These types of threads are slow and inefficient. Because, thread operations are hundreds of times slower than user-level threads.
Since kernel is going to manage and schedule threads as well as processes. It requires a full thread control block for each thread to maintain information about threads. This result in significant overhead and increases in kernel complexity.
- Related Articles
- How to implement thread in user space?
- How can we implement a timer thread in Java?
- Implement Runnable vs Extend Thread in Java
- What is the motivation to implement a micro-kernel in an operating system?
- C# Program to implement Sleep Method Of Thread
- How to get the thread ID from a thread in C#?
- Actions taken by a kernel to context-switch between kernel-level threads.
- How a thread can interrupt another thread in Java?
- How to catch a thread's exception in the caller thread in Python?
- Kernel in Operating System
- How is the Linux kernel tested?
- How to create a thread in C#?
- How to run continues thread in android?
- How to create a thread in Java
- How to create a thread in android?
