Open in App
Not now

• Last Updated : 04 May, 2022

Prerequisites –

It is a fixed priority based algorithm in which priorities are assigned to each task based on their relative deadline. Task with shortest deadline is assigned highest priority. It is a Preemptive Scheduling Algorithm that means if any task of higher priority comes then, running task is preempted and higher priority task is assigned to CPU.

Task can be represented as shown in figure :

Example –
Suppose there are two tasks that need to be executed.
Task1 has release time 0, period 7 units, execution time 2 units, and deadline of 6 units ( T1 ( 0, 7, 2, 6 ) ). Task2 has release time 0, period 5 units, execution time 2 units, and deadline of 4 units ( T2 ( 0, 5, 2, 4 ) ).

Step by step explanation –

• At T=0 both T1 and T2 are available, but deadline (T2) < deadline (T1). So T2 gets CPU and gets executed till T=2. Now T2 will be available at T=5.
• At T=2 only T1 is available so T1 gets executed till T=4. Now T1 will be available at T=7.
• At T=4 to T=5 CPU remains idle as not task is available for execution.
• At T=5 only T2 is available so T2 gets executed till T=7. Now T2 will be available at T=10.
• At T=7 only T1 is available so T1 gets executed till T=9. Now T1 will be available at T=14.
• At T=9 to T=10 CPU remains idle as not task is available for execution.
• At T=10 only T2 is available so T2 gets executed till T=12. Now T2 will be available at T=15.
• At T=12 to T=14 CPU remains idle as not task is available for execution.
• At T=14 only T1 is available so T1 gets executed till T=15. Still 1 unit of work for T1 is remaining.
• At T=15 both T1 and T2 are available, but deadline (T2) < deadline (T1). So T2 gets CPU and gets executed till T=17. Now T2 will be available at T=20.

Complete execution process is shown in figure below –