The Wayback Machine - https://web.archive.org/web/20240619111620/https://www.geeksforgeeks.org/preemptive-and-non-preemptive-scheduling/
Open In App

Preemptive and Non-Preemptive Scheduling

Last Updated : 06 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Prerequisite – CPU Scheduling 

You will discover the distinction between preemptive and non-preemptive scheduling in this article. But first, you need to understand preemptive and non-preemptive scheduling before going over the differences.

Preemptive Scheduling

Preemptive scheduling is used when a process switches from the running state to the ready state or from the waiting state to the ready state. The resources (mainly CPU cycles) are allocated to the process for a limited amount of time and then taken away, and the process is again placed back in the ready queue if that process still has CPU burst time remaining. That process stays in the ready queue till it gets its next chance to execute. 

Algorithms based on preemptive scheduling are Round Robin (RR), Shortest Remaining Time First (SRTF), Priority (preemptive version), etc. 

 

Preemptive scheduling has a number of advantages and disadvantages. The following are preemptive scheduling’s benefits and drawbacks:

Advantages

  1. Because a process may not monopolize the processor, it is a more reliable method.
  2. Each occurrence prevents the completion of ongoing tasks.
  3. The average response time is improved.
  4. Utilizing this method in a multi-programming environment is more advantageous.
  5. The operating system makes sure that every process using the CPU is using the same amount of CPU time.

Disadvantages

  1. Limited computational resources must be used.
  2. Suspending the running process, change the context, and dispatch the new incoming process all take more time.
  3. The low-priority process would have to wait if multiple high-priority processes arrived at the same time.

Non-Preemptive Scheduling

Non-preemptive Scheduling is used when a process terminates, or a process switches from running to the waiting state. In this scheduling, once the resources (CPU cycles) are allocated to a process, the process holds the CPU till it gets terminated or reaches a waiting state. In the case of non-preemptive scheduling does not interrupt a process running CPU in the middle of the execution. Instead, it waits till the process completes its CPU burst time, and then it can allocate the CPU to another process. 

Algorithms based on non-preemptive scheduling are: Shortest Job First (SJF basically non preemptive) and Priority (nonpreemptive version), etc. 

Non-preemptive scheduling has both advantages and disadvantages. The following are non-preemptive scheduling’s benefits and drawbacks:

Advantages

  1. It has a minimal scheduling burden.
  2. It is a very easy procedure.
  3. Less computational resources are used.
  4. It has a high throughput rate.

Disadvantages

  1. Its response time to the process is super.
  2. Bugs can cause a computer to freeze up.
     

Key Differences Between Preemptive and Non-Preemptive Scheduling

  1. In preemptive scheduling, the CPU is allocated to the processes for a limited time whereas, in Non-preemptive scheduling, the CPU is allocated to the process till it terminates or switches to the waiting state.
  2. The executing process in preemptive scheduling is interrupted in the middle of execution when a higher priority one comes whereas, the executing process in non-preemptive scheduling is not interrupted in the middle of execution and waits till its execution.
  3. In Preemptive Scheduling, there is the overhead of switching the process from the ready state to the running state, vise-verse, and maintaining the ready queue. Whereas in the case of non-preemptive scheduling has no overhead of switching the process from running state to ready state.
  4. In preemptive scheduling, if a high-priorThe process The process non-preemptive low-priority process frequently arrives in the ready queue then the process with low priority has to wait for a long, and it may have to starve. , in non-preemptive scheduling, if CPU is allocated to the process having a larger burst time then the processes with a small burst time may have to starve.
  5. Preemptive scheduling attains flexibility by allowing the critical processes to access the CPU as they arrive in the ready queue, no matter what process is executing currently. Non-preemptive scheduling is called rigid as even if a critical process enters the ready queue the process running CPU is not disturbed.
  6. Preemptive Scheduling has to maintain the integrity of shared data that’s why it is cost associative which is not the case with Non-preemptive Scheduling.

Comparison Chart

Parameter                        PREEMPTIVE SCHEDULING NON-PREEMPTIVE SCHEDULING
Basic In this resources(CPU Cycle) are allocated to a process for a limited time. Once resources(CPU Cycle) are allocated to a process, the process holds it till it completes its burst time or switches to waiting state.
Interrupt Process can be interrupted in between. Process can not be interrupted until it terminates itself or its time is up.
Starvation If a process having high priority frequently arrives in the ready queue, a low priority process may starve. If a process with a long burst time is running CPU, then later coming process with less CPU burst time may starve.
Overhead It has overheads of scheduling the processes. It does not have overheads.
Flexibility flexible rigid
Cost cost associated no cost associated
CPU Utilization In preemptive scheduling, CPU utilization is high. It is low in non preemptive scheduling.
Waiting Time Preemptive scheduling waiting time is less. Non-preemptive scheduling waiting time is high.
Response Time Preemptive scheduling response time is less. Non-preemptive scheduling response time is high.
Decision making  Decisions are made by the scheduler and are based on priority and time slice allocation  Decisions are made by the process itself and the OS just follows the process’s instructions
 
Process control  The OS has greater control over the scheduling of processes  The OS has less control over the scheduling of processes
 
Overhead  Higher overhead due to frequent context switching  Lower overhead since context switching is less frequent
 
Examples Examples of preemptive scheduling are Round Robin and Shortest Remaining Time First. Examples of non-preemptive scheduling are First Come First Serve and Shortest Job First.

Conclusion

Preemptive scheduling is not better than non-preemptive scheduling, and vice versa. It all depends on how a scheduling algorithm increases CPU utilization while decreasing average process waiting time.

Frequently Asked Questions

Q.1: How is priority determined in preemptive scheduling? 

Answer:

Preemptive scheduling systems often assign priority levels to tasks or processes. The priority can be determined based on factors like the nature of the task, its importance, or its deadline. Higher-priority tasks are given precedence and are allowed to execute before lower-priority tasks.

Q.2: What happens in non-preemptive scheduling if a task does not yield the CPU? 

Answer:

In non-preemptive scheduling, if a task does not voluntarily yield the CPU, it can lead to a situation called a “starvation” or “deadlock” where other tasks are unable to execute. To avoid such scenarios, it’s important to ensure that tasks have mechanisms to release the CPU when necessary, such as waiting for I/O operations or setting maximum execution times.



Previous Article
Next Article

Similar Reads

Difference between Preemptive Priority based and Non-preemptive Priority based CPU scheduling algorithms
Prerequisite - CPU Scheduling Priority Scheduling : In priority scheduling, each process has a priority which is an integer value assigned to it. The smallest integer is considered as the highest priority and the largest integer is considered as the lowest priority. The process with the highest priority gets the CPU first. In rare systems, the larg
4 min read
Difference Between Preemptive and Non-Preemptive CPU Scheduling Algorithms
Preemptive scheduling permits a high-priority task to interrupt a running process, When a process transitions from the running to the ready or from the waiting to the ready states, preemptive scheduling is used. Whereas in non-preemptive scheduling, any new process must wait until the running process completes its CPU cycle. In this article, we wil
5 min read
Difference between Preemptive and Non-Preemptive Kernel in OS
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 yiel
4 min read
First Come First Serve – CPU Scheduling (Non-Preemptive)
Simplest CPU scheduling algorithm that schedules according to arrival times of processes. The first come first serve scheduling algorithm states that the process that requests the CPU first is allocated the CPU first. It is implemented by using the FIFO queue. When a process enters the ready queue, its PCB is linked to the tail of the queue. When t
11 min read
Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non- preemptive)
The shortest job first (SJF) or shortest job next, is a scheduling policy that selects the waiting process with the smallest execution time to execute next. SJN, also known as Shortest Job Next (SJN), can be preemptive or non-preemptive. Characteristics of SJF Scheduling: Shortest Job first has the advantage of having a minimum average waiting time
13 min read
Shortest Job First (or SJF) CPU Scheduling Non-preemptive algorithm using Segment Tree
Shortest job first (SJF) or shortest job next, is a scheduling policy that selects the waiting process with the smallest execution time to execute next. SJN is a non-preemptive algorithm.   Shortest Job first has the advantage of having a minimum average waiting time among all scheduling algorithms.It is a Greedy Algorithm.It may cause starvation i
15+ min read
Relation in FCFS and Preemptive Priority Scheduling Algorithm
In this article, we will see how FCFS is a special kind of Priority Preemptive Scheduling Algorithm. Also, we will cover the relation with each other. Let us discuss one by one. 1. First Come First Serve (FCFS) Scheduling Algorithm : FCFS is the simplest of CPU Scheduling Algorithm which executes the process that comes first. It is a non-preemptive
4 min read
Relation between Preemptive Priority and Round Robin Scheduling Algorithm
In this article, we'll try to establish the relation between Round Robin and Preemptive Priority Scheduling Algorithm. Let's discuss the algorithms one by one first and then establish how Round Robin is a special kind of Preemptive Priority Scheduling Algorithm. Prerequisite - CPU Scheduling | Difference between Priority and Round Robin (RR) Schedu
2 min read
Program for Preemptive Priority CPU Scheduling
Implementing priority CPU scheduling. In this problem, we are using Min Heap as the data structure for implementing priority scheduling. In this problem smaller numbers denote higher priority. The following functions are used in the given code below: struct process { processID, burst time, response time, priority, arrival time.} void quicksort(proc
15+ min read
Longest Remaining Time First (LRTF) or Preemptive Longest Job First CPU Scheduling Algorithm
Longest Remaining Time First (LRTF) is a preemptive version of Longest Job First (LJF) scheduling algorithm. In this scheduling algorithm, we find the process with the maximum remaining time and then process it, i.e. check for the maximum remaining time after some interval of time(say 1 unit each) to check if another process having more Burst Time
7 min read