Round Robin Algorithm
Round Robin Algorithm
The Round Robin scheduling algorithm is a preemptive scheduling algorithm where each
process gets executed for a small unit of time called a time quantum (TQ). If a process
doesn't finish its execution within its time quantum, it is preempted and moved to the end
of the ready queue, allowing the next process to execute. This continues until all processes
are completed.
Given the processes (P1, P2, P3, P4) with their respective arrival times (0, 1, 2, 4), burst times
(5, 4, 2, 1) and using a time quantum (TQ) of 2 hours, let's walk through the scheduling:
P AT BT
Criteria= TQ
P1 0 5
Mode= Preemptive
P2 1 4
P3 2 2
P4 4 1
➢ Time 0:
• Ready Queue: [P1]
• Gantt Chart: | P1 |
• P1 starts execution and uses the CPU for 2 hours (TQ).
• P1 remaining burst time: 5 - 2 = 3 hours.
• Next Ready Queue: [P2]
➢ Time 2:
• Ready Queue: [P2, P1]
• Gantt Chart: | P1 | P2 |
• P1 is preempted and added to the end of the queue. P2 starts execution and
uses the CPU for 2 hours.
• P2 remaining burst time: 4 - 2 = 2 hours.
• Next Ready Queue: [P1, P3]
➢ Time 4:
• Ready Queue: [P1, P3, P2]
• Gantt Chart: | P1 | P2 | P3 |
• P2 is preempted and added to the end of the queue. P3 starts execution and
uses the CPU for 2 hours.
• P3 remaining burst time: 2 - 2 = 0 hours (P3 completes execution).
• Next Ready Queue: [P1, P2]
➢ Time 6:
• Ready Queue: [P1, P2]
• Gantt Chart: | P1 | P2 | P3 | P1 |
• P3 completes execution and leaves the queue. P1 resumes execution and uses
the CPU for 2 hours.
• P1 remaining burst time: 3 - 2 = 1 hour.
• Next Ready Queue: [P2, P4]
➢ Time 8:
• Ready Queue: [P2, P4, P1]
• Gantt Chart: | P1 | P2 | P3 | P1 | P4 |
• P1 is preempted and added to the end of the queue. P4 starts execution and
uses the CPU for 1 hour (completes execution).
• P4 remaining burst time: 1 - 1 = 0 hours (P4 completes execution).
• Next Ready Queue: [P2, P1]
➢ Time 9:
• Ready Queue: [P2, P1]
• Gantt Chart: | P1 | P2 | P3 | P1 | P4 | P2 |
• P4 completes execution and leaves the queue. P2 resumes execution and uses
the CPU for 2 hours.
• P2 remaining burst time: 2 - 2 = 0 hours (P2 completes execution).
• Next Ready Queue: [P1]
➢ Time 11:
• Ready Queue: [P1]
• Gantt Chart: | P1 | P2 | P3 | P1 | P4 | P2 | P1 |
• P2 completes execution and leaves the queue. P1 resumes execution and uses
the CPU for 1 hour.
• P1 remaining burst time: 1 - 1 = 0 hours (P1 completes execution).
➢ Time 12:
• Ready Queue: []
• Gantt Chart: | P1 | P2 | P3 | P1 | P4 | P2 | P1 |
• All processes have completed execution.
Calculations:
➢ Turn-around time (TAT) = Completion Time - Arrival Time
➢ Waiting time (WT) = Turn-around Time - Burst Time
➢ Response time (RT) = First time it got CPU - Arrival Time
P AT BT CT TAT WT RT
P1 0 5 12 12 7 0
P2 1 4 11 10 6 1
P3 2 2 6 4 2 2
P4 4 1 9 5 4 4
RQ (ready queue)
P1 P2 P3 P1 P4 P2 P1
GANTT CHART
P1 P2 P3 P1 P4 P2 P1
0 2 4 6 8 9 11 12