Open In App

Difference between Preemptive and Non-Preemptive Kernel in OS

Improve
Improve
Like Article
Like
Save
Share
Report

Introduction :

A kernel is the central component of an operating system that manages system resources and provides a layer of abstraction between the hardware and software. One of the key design decisions for a kernel is whether it is preemptive or non-preemptive.

A non-preemptive kernel, also known as a cooperative kernel, relies on processes yielding control voluntarily. In other words, a process that is currently running must explicitly give up the CPU before another process can run. This means that a process can monopolize the CPU if it doesn’t yield control, potentially causing other processes to starve for resources. Non-preemptive kernels are simpler and require less overhead, but they may not be suitable for systems that require guaranteed response times.

A preemptive kernel, on the other hand, can interrupt a running process and force it to yield the CPU to another process. This allows the kernel to allocate resources fairly and ensure that no process monopolizes the CPU. Preemptive kernels are more complex and require more overhead, but they provide better responsiveness and are better suited for real-time systems.

1. Preemptive Kernel :
Preemptive Kernel, as name suggests, is a type of kernel that always executes the highest priority task that are ready to run. It cannot use-non-reentrant functions unless and until functions are mutual exclusive.

Example : Linux 2-6

2. Non-Preemptive Kernel :
Non-Preemptive Kernel, as name suggests, is a type of kernel that is free from race conditions on kernel data structures as only one process is active in kernel at a time. It is considered as a serious drawback for real time applications as it does not allow preemption of process running in kernel mode.

Example : Linux 2.4

Difference between Preemptive and Non-Preemptive Kernel in OS :

Preemptive Kernel 

 Non-Preemptive Kernel 

It is a process that might be replaced immediately.  It is a process that continues to run until it finishes handling execution handler or voluntarily relinquishes CPU. 
It is more suitable for real time programming as compared to non-preemptive kernels.   It is less suitable for real-time programming as compared to preemptive kernel.  
In this, higher priority task that are ready to run is given CPU control.   In this, each and every task are explicitly given up CPU control.  
It generally allows preemption even in kernel mode.   It generally does not allow preemption of process running in kernel mode.  
Responsive time is deterministic and is more responsive as compared to non-preemptive kernel. Response time is nondeterministic and is less responsive as compared to preemptive kernel.
Higher priority task becomes ready, currently running task is suspended and moved to ready queue. Higher priority task might have to wait for long time.  
It does not require semaphores.   Shared data generally requires semaphores.  
It cannot use non-reentrant code.   It can use non-reentrant code.  
It is more difficult to design preemptive kernels as compared to non-preemptive kernel. It is less difficult to design non-preemptive kernels as compared to preemptive kernels.  
They are more secure and more useful in real-world scenarios.   They are less secure and less useful in real-world scenarios. 
Can interrupt a running process and force it to yield the CPU to another process  Relies on processes yielding control voluntarily
 
Allocates resources fairly and ensures that no process monopolizes the CPU  May not allocate resources fairly, and a process can monopolize the CPU if it doesn’t yield control
 
Provides better responsiveness and is better suited for real-time systems  Simpler and requires less overhead, but may not be suitable for systems that require guaranteed response times
 
More complex and requires more overhead  Less complex and requires less overhead
 
Suitable for real-time systems such as embedded systems and critical infrastructure  Suitable for non-real-time systems such as desktop computers and servers

 

  

 


Last Updated : 02 May, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads