Courses

Longest Remaining Time First (LRTF) CPU Scheduling Algorithm Notes | EduRev

GATE : Longest Remaining Time First (LRTF) CPU Scheduling Algorithm Notes | EduRev

The document Longest Remaining Time First (LRTF) CPU Scheduling Algorithm Notes | EduRev is a part of the GATE Course Operating System.
All you need of GATE at this link: GATE

This is a pre-emptive version of Longest Job First (LJF) scheduling algorithm. In this scheduling algorithm, we find the process with the maximum remaining time and then process it. We check for the maximum remaining time after some interval of time(say 1 unit each) to check if another process having more Burst Time arrived up to that time.

Procedure:

• Step-1: First, sort the processes in increasing order of their Arrival Time.
• Step-2: Choose the process having least arrival time but with most Burst Time. Then process it for 1 unit. Check if any other process arrives upto that time of execution or not.
• Step-3: Repeat the above both steps until execute all the processes.

Example 1: Consider the following table of arrival time and burst time for four processes P1, P2, P3 and P4.

Working: (for input 1):

1. At t = 1, Available Process : P1. So, select P1 and execute 1 ms.
2. At t = 2, Available Process : P1, P2. So, select P2 and execute 1 ms (since BT(P1) = 1 which is less than BT(P2) = 4)
3. At t = 3, Available Process : P1, P2, P3. So, select P3 and execute 1 ms (since, BT(P1) = 1 , BT(P2) = 3 , BT(P3) = 6).
4. Repeat the above steps until the execution of all processes.

Note that CPU will be idle for 0 to 1 unit time since there is no process available in the given interval.

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)

Therefore, final table look like,

Output:
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 = 48 / 4 = 12.00 ms

Example 2: Consider the following table of arrival time and burst time for four processes P1, P2, P3, P4 and P5.

Similarly example-1, Gantt chart for this example,

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)

Therefore, final table look like,

Output:
Total Turn Around Time = 61 ms
So, Average Turn Around Time = 61 / 5 = 12.20 ms
And, Total Waiting Time = 45 ms
So, Average Waiting Time = 45 / 5 = 9.00 ms

Offer running on EduRev: Apply code STAYHOME200 to get INR 200 off on our premium plan EduRev Infinity!

69 docs|23 tests

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

,

;