Prerequisite – CPU Scheduling | Longest Remaining Time First (LRTF) algorithm
We have given some process with arrival time and Burst Time and we have to find the completion time (CT), Turn Around Time(TAT), Average Turn Around Time (Avg TAT), Waiting Time(WT), Average Waiting Time (AWT) for the given processes.
Example: Consider the following table of arrival time and burst time for four processes P1, P2, P3 and P4.
Process Arrival time Burst Time P1 1 ms 2 ms P2 2 ms 4 ms P3 3 ms 6 ms p4 4 ms 8 ms
Gantt chart will be as following below,
Since, complietion time (CT) can be directly determined by Gantt chart, and
Turn Around Time (TAT) = (Complition Time) - (Arival Time) Also, Waiting Time (WT) = (Turn Around Time) - (Burst Time)
Total Turn Around Time = 68 ms So, Average Turn Around Time = 68/4 = 17.00 ms And, Total Waiting Time = 48 ms So, Average Waiting Time = 12.00 ms
- Step-1: Create a structure of process containing all necessary fields like AT (Arrival Time), BT(Burst Time), CT(Completion Time), TAT(Turn Around Time), WT(Waiting Time).
- Step-2: Sort according to the AT;
- Step-3: Find the process having Largest Burst Time and execute for each single unit. Increase the total time by 1 and reduce the Burst Time of that process with 1.
- Step-4: When any process have 0 BT left, then update the CT(Completion Time of that process CT will be Total Time at that time).
- Step-2: After calculating the CT for each process, find TAT and WT.
(TAT = CT - AT) (WT = TAT - BT)
Implementation of Algorithm –
PNo AT BT 1 1 2 2 2 4 3 3 6 4 4 8 Process executing at time 1 is: P1 Process executing at time 2 is: P2 Process executing at time 3 is: P3 Process executing at time 4 is: P4 Process executing at time 5 is: P4 Process executing at time 6 is: P4 Process executing at time 7 is: P3 Process executing at time 8 is: P4 Process executing at time 9 is: P3 Process executing at time 10 is: P4 Process executing at time 11 is: P2 Process executing at time 12 is: P3 Process executing at time 13 is: P4 Process executing at time 14 is: P2 Process executing at time 15 is: P3 Process executing at time 16 is: P4 Process executing at time 17 is: P1 Process P1 is completed at 18 Process executing at time 18 is: P2 Process P2 is completed at 19 Process executing at time 19 is: P3 Process P3 is completed at 20 Process executing at time 20 is: P4 Process P4 is completed at 21 After execution of all processes ... PNo AT BT CT TAT WT 1 1 2 18 17 15 2 2 4 19 17 13 3 3 6 20 17 11 4 4 8 21 17 9 Total TAT = 68 Average TAT = 17 Total WT = 48 Average WT = 12
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Longest Remaining Time First (LRTF) CPU Scheduling Algorithm
- LRTF Scheduling Full Form
- Difference between Seek Time and Transfer Time in Disk Scheduling
- Least Slack Time (LST) scheduling Algorithm in real-time systems
- Difference between Turn Around Time (TAT) and Waiting Time (WT) in CPU Scheduling
- Difference between Arrival Time and Burst Time in CPU Scheduling
- Introduction of Shortest Remaining Time First (SRTF) algorithm
- Difference between Seek Time and Disk Access Time in Disk Scheduling
- Difference between Transfer Time and Disk Access Time in Disk Scheduling
- Priority CPU Scheduling with different arrival time - Set 2
- Scheduling in Real Time Systems
- Job Scheduling with two jobs allowed at a time
- Shortest Job First CPU Scheduling with predicted burst time
- Difference between Rotational Latency and Transfer Time in Disk Scheduling
- Difference between Seek Time and Rotational Latency in Disk Scheduling
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.
Improved By : SHUBHAMSINGH10