Preemptive and Non-Preemptive Scheduling
Preemptive and Non-Preemptive Scheduling
Scheduling
Last Updated : 12 Jul, 2024
In operating systems, scheduling is the method by which processes are given access to system
resources, primarily the CPU. Efficient scheduling is essential for optimal system
performance and user satisfaction. There are two primary types of CPU scheduling:
preemptive and non-preemptive.
Algorithms based on preemptive scheduling are Round Robin (RR), Shortest Remaining
Time First (SRTF), Priority (preemptive version), etc.
Preemptive Scheduling
Because a process may not monopolize the processor, it is a more reliable method.
The operating system makes sure that every process using the CPU is using the same
amount of CPU time.
Suspending the running process, change the context, and dispatch the new incoming
process all take more time.
Algorithms based on non-preemptive scheduling are: Shortest Job First (SJF basically non
preemptive) and Priority (nonpreemptive version), etc.
Advantages of Non-Preemptive Scheduling
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.
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.
Conclusion
Preemptive scheduling allows the operating system to interrupt and reassign the CPU to
different processes, making it responsive and efficient for high-priority tasks. Non-
preemptive scheduling lets processes run to completion without interruption, simplifying the
system but potentially causing delays for other tasks. The choice between these methods
depends on the system’s needs for performance and simplicity.
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.
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.
Preemptive scheduling is generally better for real-time systems because it allows high-
priority tasks to be addressed immediately, meeting the time-sensitive requirements of such
systems.