Difference between Preemptive and Non-Preemptive Scheduling
The CPU might be idle, but it still queues processes to run. During its inactive state, the CPU scheduler scans the queue to pick a process for the CPU. The chosen process runs and finishes all CPU operations on time. The operating system runs one process to make the system run faster and more efficiently. Meanwhile, other processes remain in the queue, waiting for their turn, due to the lack of I/O resources. The CPU scheduler chooses a process from available memory processes and assigns it to the CPU for execution. Preemptive and non-preemptive scheduling are two major scheduling algorithms.
- When a process transitions from standby to ready for execution, it is called preemptive scheduling.
- When a process eliminates or transitions from running to standby, the CPU scheduler uses non-preemptive scheduling.
- Pros and Cons of Preemptive vs Non-Preemptive Scheduling.
- The CPU scheduler relies on preemptive and non-preemptive scheduling styles to assign processes to the CPU and run the operating system.
When does the CPU scheduler schedule processes?
The CPU schedules processes when either one or all of the following incidents occur:
- When a process transitions from execution to standby.
- When a process moves from running to ready due to an interruption.
- When a process switches from standby to ready state.
- When a process finishes.
During the first and the last situations, the CPU immediately picks a process for execution. However, when a process moves from either running to ready or standby to ready, the scheduler must decide which scheduling technique to choose. The former calls for non-preemptive scheduling, whereas the latter requires preemptive scheduling. Unlike preemptive scheduling, non-preemptive scheduling only allocates a process to the CPU when the current task finishes its burst time and is terminated or moved to a waiting state.
What is Preemptive Scheduling?
When a process transitions from standby to ready for execution, it is called preemptive scheduling. This schedule style assigns processes to the CPU based on their priority. Suppose a high-priority process suddenly enters the queue. Instead of waiting for its turn, it will replace the current process and execute it first. The current process will pause its performance and remain on standby until the high-priority task completes CPU functions.
Due to high-priority processes performing first, the rest of the processes receive extra time. As a result, the transitioning process is accelerated. It moves from standby to ready, making the operative system flexible. Furthermore, preemptive scheduling makes it seem like multiple programs run simultaneously, despite high-priority processes going first.
(Image Credit: ScienceDirect)
Preemptive Scheduling Algorithms
- SRTF – Shortest Remaining Time First: This algorithm assigns the highest priority to the process with the earliest deadline.
- RR – Round Robin: A time-sharing algorithm in which each process is given a fixed time slot in a cyclic order. It ensures that every process gets a fair share of CPU time.
- PPS – Priority Preemptive Scheduler: A scheduling algorithm that assigns a priority to each process, and the process with the highest priority is executed first.
- RMS – Rate Monotonic Scheduling: This algorithm assigns priority to the process based on the period of the process. Here, processes with shorter periods have a higher priority.
- LLF – Least Laxity First: This algorithm assigns priority to a process based on the difference between the process’s relative deadline and its execution time.
What are the Pros and Cons of Preemptive Scheduling?
This schedule style comes with its own set of advantages and disadvantages.
Pros of Preemptive Scheduling
- Since it is an organized process, it prevents a single process from using all CPU resources and space.
- Once the current process pauses, the scheduler reviews the running operation.
- The OS ensures that all queued and running processes receive extra and adequate CPU time.
- Preemptive scheduling accelerates the response time.
- It runs multiple processes simultaneously, making it a vital tool for performing multi-programming tasks.
Cons of Preemptive Scheduling
- The CPU scheduler dedicates additional time to halting the current process, replacing it with a high-priority task, and queuing incoming processes.
- If multiple high-priority processes enter the queue, it ceases low-priority operations, causing them to remain on standby for longer. In such cases, the operating system’s efficiency reduces.
What is Non-Preemptive Scheduling?
When a process eliminates or transitions from running to standby, the CPU scheduler uses non-preemptive scheduling. Once the CPU allocates available resources, the process uses the CPU’s space until it stops or switches to waiting. Unlike preemptive scheduling, where a low-priority process is interrupted, the non-preemptive style does not pause ongoing operations. Instead, it allows processes to finish executing before assigning another to the CPU.
In case a process is in the middle of execution, it will either terminate to free the CPU or automatically shift to standby. If a process under non-preemptive scheduling has a long running time, the scheduler will not interrupt it. Since the CPU scheduler lets it run and queues the remaining processes, it increases their waiting time.
Non-Preemptive Scheduling Algorithms
- Priority non-preemptive scheduling: A scheduling algorithm that assigns a priority to each process, and the process with the highest priority is executed first. Here, once a process starts executing, it cannot be interrupted.
- FCFS – First-come-first-served: This algorithm executes the process that comes first in the queue.
- SJF – Shortest Job First: This algorithm assigns the highest priority to the process with the shortest execution time.
- LJF – Longest Job First: This algorithm assigns the highest priority to the process with the longest execution time.
- SRT – Shortest Remaining Time: This algorithm assigns the highest priority to the process with the shortest remaining execution time.
What are the Pros and Cons of Non-Preemptive Scheduling?
Similar to preemptive scheduling, non-preemptive scheduling also has its advantages and disadvantages.
Pros of Non-Preemptive Scheduling
- Produces high-quality results and an increased throughput
- Easy to perform and execute
- Reduces scheduling overhead
- It uses fewer CPU resources compared to preemptive scheduling
Cons of Non-Preemptive Scheduling
- Increases immediate or high-priority operations completion time, as it does not interrupt current processes.
- Low response time allows bugs to affect the system.
- Process performance time is slower.
Uses of preemptive scheduling:
- Allows a higher-priority task to interrupt a lower-priority task currently being executed.
- It can be used in real-time systems where certain tasks must be completed within a specific timeframe.
- Useful for systems with multiple users or processes that need to share resources.
Uses of non-preemptive scheduling:
- Tasks are allowed to run to completion without interruption.
- It can be used in systems where it is important to maintain data consistency.
- Useful for systems where tasks have a fixed order of execution.
- Useful in situations where the system needs to guarantee that a task will be completed before starting another one.
Preemptive and Non-Preemptive Scheduling: A Comparative Study
Preemptive and Non-Preemptive Scheduling: A Comparative Study
Apart from the fundamental differences in their operations, preemptive and non-preemptive schedules differ in various parameters. When questioning, “Which is better: preemptive or non-preemptive scheduling?” there is no definite answer. The process you choose depends on your programming environment and priority tasks. The following parameters of Preemptive vs Non-Preemptive Scheduling will make it easier for you to decide which scheduling style fits your processes the best.
|Basis of Comparison||Preemptive scheduling||Non-preemptive scheduling|
|Process interruption||You can interrupt the current process at any time.||You cannot stop ongoing processes. You must wait for the current process to terminate or switch to standby.|
|Resource allocation||Low-priority processes might not receive adequate resources due to high-priority processes taking their place.||If processes with long burst times monopolize CPU resources, other processes might starve.|
|Overhead performance||Overheads allow a process to switch from its current state to waiting or ready.||This scheduling style does not contain overheads.|
|Flexibility||This incredibly flexible schedule allows you to interrupt or pause processes easily.||Non-preemptive scheduling is not flexible, as you cannot switch ongoing processes.
|CPU monopolization||Since preemptive scheduling modifies process queues, it overworks the CPU.||Less CPU space and energy are used.
|Algorithms||Preemptive scheduling has three algorithms: Priority, Round Robin, and Shortest Remaining Time First.||Non-preemptive scheduling has three processes: Priority, First-come-first-served, and Shortest Job First.|
|Response time||Has a lower response time||Has a longer response time|
In this article, Preemptive vs. Non-Preemptive Scheduling, the CPU scheduler relies on preemptive and non-preemptive scheduling styles to assign processes to the CPU and run the operating system. The former technique gives a task to the CPU for a specific period. It allows the scheduler to interrupt ongoing processes to accommodate high-priority ones. On the other hand, non-preemptive scheduling executes a process until it terminates or transitions to a standby state. So this was an overview of Preemptive vs. Non-Preemptive Scheduling.
In this article, you learned about Preemptive and Non-Preemptive Scheduling. To know more about the topic, you can refer to these articles –