Preemptive Scheduling


In an operating system (OS), a process scheduler performs scheduling of process. It includes switching of processes between the ready queue and waiting queue and allocating them to the CPU. The operating system assigns priority to each process and maintains these queues. The scheduler selects the process from the queue and loads it into memory for execution. This process scheduling takes place in two types: preemptive scheduling and non-preemptive scheduling.

Preemptive Scheduling

In preemptive scheduling, a low priority process gets suspended from its execution, if a high priority process is waiting in the same queue for its execution. It is used when a process or task switches from running state to ready state or from waiting state to ready state. In this scheduling, the higher priority process is executed first.

At times, it is necessary to run a process that has a higher priority. If a high priority process arrives in the ready queue, it does not have to wait for the current process to complete its burst time. Instead, the running process is interrupted and is placed in the ready queue until the process with high priority is utilizing the CPU cycles. In this way, each process in the ready queue gets some time to run CPU. This is called Preemptive scheduling.

Preemptive Scheduling  Example

P1 and P2 have different arrival times in the queue. Based on their priority or burst time, these processes are interrupted and allocated to the CPU. A process P1 arrives at time 0 and is allocated the CPU. Process P2 arrives at time 2, before P1 finishes execution. See the table below.

ProcessArrival time Burst time

Preemptive Scheduling example

Learn more about preemptive scheduling through Shortest Job First Scheduling (SJF) algorithm here.

Types of Preemptive Scheduling algorithms

Shortest Job First (SJF) Scheduling

It is also called the Greedy In Preemptive Shortest Job First Scheduling, the processes are put into the ready queue as per their arrival time. When a process with the shortest burst time arrives, the existing process is removed from execution, and the process with the shortest burst time is executed first.

Round-Robin (RR) Scheduling

It is also called time-slicing scheduling. It is primarily designed for a time-sharing In Round-Robin (RR) Scheduling, the process is allocated to the CPU for the specific time period (time slice). If the process completes its execution within this time period, then it is removed from the queue or else it has to wait for another time slice.

Please Login/Signup to comment