Preemptive Scheduling
About Preemptive Type scheduling
On this page, we will learn the concepts of preemptive scheduling with the help of detailed explanation along with examples. Preemptive scheduling is a type of scheduling process which helps to schedule tasks with higher priority first and then the tasks with comparatively lower priority.
Overview
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 type of scheduling algorithm, 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.
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. [table id=628 /] Learn more about preemptive type scheduling algorithms 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.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment