Difference between Preemptive and Non-preemptive CPU scheduling algorithms
In CPU Scheduling, we have two types of schedulea , Let’s have a look at them:
Preemptive Scheduling: In this, a scheduler may preempt a low-priority running process anytime when a high-priority process enters into a ready state. When scheduling takes from either of the below circumstances it is preemptive scheduling –
- When a process switches from the running state to the ready state (for example, when an interrupt occurs).
- When a process switches from the waiting state to the ready state (for example, at the completion of I/)).
Non-Preemptive Scheduling: In this, once a process enters the running state it cannot be preempted until it completes it’s allocation time. When scheduling takes place only under the below circumstances we say that the scheduling scheme is non-preemptive or cooperative.
- When a process switches from the running state to the waiting state (for example, as the result of an I/O request or an invocation of wait() for the termination of a child process).
- When a process terminates.
Let us see the difference between Preemptive Scheduling and Non-Preemptive Scheduling:
|Preemptive Scheduling||Non-Preemptive Scheduling|
|The CPU is allocated to the processes for a certain amount of time.||The CPU is allocated to the process till it ends its the fewer execution or switches to waiting state.|
|The executing process here is interrupted in the middle of execution.||The executing process here is not interrupted in the middle of execution.|
|It usually switches the process from the ready state to the running state, vice-versa, and maintains the ready queue.||It does not switch the process from running state to a ready state.|
|Here, if a process with high priority frequently arrives in the ready queue then the process with low priority has to wait for long, and it may have to starve.||Here, if CPU is allocated to the process with a larger burst time then the processes with a small burst time may have to starve.|
|It is quite flexible because the critical processes are allowed to access CPU as they arrive into the ready queue, no matter what process is executing currently.||It is rigid as even if a critical process enters the ready queue the process running CPU is not disturbed.|
|This is cost associative as it has to maintain the integrity of shared data.||This is not cost associative.|
|This scheduling leads to more context switches.||This scheduling leads to less context switches compared to preemptive scheduling.|
|Preemptive scheduling allows a process to be interrupted in the midst of its execution, taking the CPU away and allocating it to another process.||Non-preemptive scheduling ensures that a process relinquishes control of the CPU only when it finishes with its current CPU burst.|
|Preemptive scheduling incurs a cost associated with accessing shared data.||Non-preemptive scheduling does not increase the cost.|
|It also affects the design of the operating system Kernel.||It does not affect the design of the OS kernel.|
|Preemptive scheduling is more complex.||Simple, but very inefficient.|
|Example: Round robin method.||Example: First come first serve method.|
Preemptive scheduling is better than non-preemptive scheduling or vice-versa can’t be said definitely. It depends on how scheduling minimizes the average waiting time of the processes and maximizes CPU utilization.
Please Login to comment...