Longest Remaining Time First (LRTF) CPU Scheduling Program
We have given some processes 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.
Prerequisite: CPU Scheduling | Longest Remaining Time First (LRTF) algorithm
LRTF is a preemptive scheduling algorithm. Its tie-breaker is FCFS and if FCFS does not breaks the tie then, we use process id as the tie-breaker.
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 completion time (CT) can be directly determined by Gantt chart, and
Turn Around Time (TAT) = (Completion Time) - (Arrival 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 the processes according to their arrival time (AT).
- Step 3: Initialize the current time (time variable) as 0, and find the process with the largest burst time (BT) among all the processes that have arrived till now. Execute that process for each single unit, i.e., increase the time variable by 1 and reduce the BT of that process by 1.
- Step 4: If any process completes its execution, update its CT(Completion Time) as the current time (time variable).
- Step 5: If the BT of the executing process becomes 0, then update its CT as the current time (time variable) and remove it from the list of processes to be executed.
- Step 6: If all processes have been executed, exit the loop.
- Step 7: After calculating the CT for each process, find the TAT (Turn Around Time) and WT (Waiting Time).
(TAT = CT - AT) (WT = TAT - BT)
Implementation of Algorithm3s
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
My Personal Notes arrow_drop_up
Please Login to comment...