# Earliest Deadline First (EDF) CPU scheduling algorithm

**Earliest Deadline First (EDF)** is an optimal dynamic priority scheduling algorithm used in real-time systems.

It can be used for both static and dynamic real-time scheduling.

EDF uses priorities to the jobs for scheduling. It assigns priorities to the task according to the absolute deadline. The task whose deadline is closest gets the highest priority. The priorities are assigned and changed in a dynamic fashion. EDF is very efficient as compared to other scheduling algorithms in real-time systems. It can make the CPU utilization to about 100% while still guaranteeing the deadlines of all the tasks.

EDF includes the kernel overload. In EDF, if the CPU usage is less than 100%, then it means that all the tasks have met the deadline. EDF finds an optimal feasible schedule. The feasible schedule is one in which all the tasks in the system are executed within the deadline. If EDF is not able to find a feasible schedule for all the tasks in the real-time system, then it means that no other task scheduling algorithms in real-time systems can give a feasible schedule. All the tasks which are ready for execution should announce their deadline to EDF when the task becomes runnable.

EDF scheduling algorithm does not need the tasks or processes to be periodic and also the tasks or processes require a fixed CPU burst time. In EDF, any executing task can be preempted if any other periodic instance with an earlier deadline is ready for execution and becomes active. Preemption is allowed in the Earliest Deadline First scheduling algorithm.

**Example:**

Consider two processes P1 and P2.

Let the period of P1 be p_{1} = 50

Let the processing time of P1 be t_{1} = 25

Let the period of P2 be period_{2} = 75

Let the processing time of P2 be t_{2} = 30

**Steps for solution:**

- Deadline pf P1 is earlier, so priority of P1>P2.
- Initially P1 runs and completes its execution of 25 time.
- After 25 times, P2 starts to execute until 50 times, when P1 is able to execute.
- Now, comparing the deadline of (P1, P2) = (100, 75), P2 continues to execute.
- P2 completes its processing at time 55.
- P1 starts to execute until time 75, when P2 is able to execute.
- Now, again comparing the deadline of (P1, P2) = (100, 150), P1 continues to execute.
- Repeat the above steps…
- Finally at time 150, both P1 and P2 have the same deadline, so P2 will continue to execute till its processing time after which P1 starts to execute.

## Recommended Posts:

- LOOK Disk Scheduling Algorithm
- C-LOOK Disk Scheduling Algorithm
- C-SCAN Disk Scheduling Algorithm
- Program for SSTF disk scheduling algorithm
- Longest Remaining Time First (LRTF) CPU Scheduling Algorithm
- Shortest Job First (or SJF) CPU Scheduling Non-preemptive algorithm using Segment Tree
- Difference between First Come First Served (FCFS) and Round Robin (RR) Scheduling Algorithm
- Least Slack Time (LST) scheduling Algorithm in real-time systems
- Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling
- Program for Banker's Algorithm | Set 1 (Safety Algorithm)
- Program for Priority CPU Scheduling | Set 1
- Program for FCFS CPU Scheduling | Set 1
- Disk Scheduling Algorithms
- CPU Scheduling in Operating Systems
- First Come, First Serve – CPU Scheduling | (Non-preemptive)

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.