Preemptive and Non-Preemptive Algorithm in Operating System

Preemptive Scheduling Algorithm

Here, a scheduler can preempt a running low-priority process at any time when a high-priority process enters a ready state. In preemptive systems, the OS takes the processor away from a running process.

If the algorithm assumes one of the following circumstances, it is a preemptive algorithm –

  • When a process transitions from the running state to the ready state.
  • When a process transitions from the wait state to the ready state.

Some algorithms of preemptive scheduling algorithms are Round Robin, shortest Remaining Time First, and priority scheduling. This scheduling algorithm is cost associated. In preemptive, low-priority processes have to suffer from starvation.

Non-preemptive Scheduling Algorithm

Once a process enters the execution state, it cannot be brought forward until it has completed its allocation time. With non-preemptive OS, the process itself decides whether it wants to leave the processor. CPU can only be taken away from a process when it is terminated or blocked. A process can occupy the CPU as long as it wants.

If planning takes place only under the following circumstances, we say that the planning scheme is non-preemptive or cooperative –

  • When a process transitions from the running state to the waiting state.
  • When a process exits.

Algorithms based on non-preemptive scheduling are shortest job first and priority (non-preemptive in some conditions).  This scheduling algorithm is no cost associated. The process which has low burst time may suffer from starvation in non-preemptive scheduling algorithm.