Round Robin
CPU Scheduling
Algorithm
Presented By:
Muhammad Nazir(2021-CS-8)
Muhammad Umar(2021-CS-24)
Outlines
Introduction
Preemptive Algorithm
Non Preemptive Algorithm
CT, TAT, RT, WT (Times)
Code Snippets
Example
Conclusion
Round Robin is a CPU scheduling Preemptive
algorithm in operating systems, in which each process
is assigned a fixed time unit, called time quantum.
Introduction
The CPU is rotated among the processes in a circular
order, ensuring that each process gets an equal share of
CPU time.
A preemptive algorithm is one that
allows a higher priority process to
interrupt and stop the execution of a
lower priority process
Preemptive and
Non-Preemptive
Algorithms A non-preemptive algorithm, on the
other hand, is one that does not
allow a running process to be
interrupted.
Completion time is the time when a process
completes execution.
Completion, Turn Around time is the total time between process
Turn Around, arrival and completion.
Response and Response time is the time between process arrival
and first response from the system.
Waiting Times
Waiting time is the total time a process spends
waiting in the ready queue.
General Formulas
In this algorithm, we take each process to ready queue and goes to running queue.
Ready 2s Running
Queue Queue
Important Formulas:
• TAT =CT-AT
• WT = TAT-BT
• RT= CPU First Time in Running Queue - AT
Example1 (For Different Arrival Time)
Process No Arrival Time (AT) Burst Time (BT)
P1 0 5
P2 1 4
P3 2 2
P4 4 1
Example1
Quantum = 2
Ready Queue:
P1 P2 P3 P1 P4 P2 P1
T=0
Running Queue:
P1 P2 P3 P1 P4 P2 P1
T=0 2 4 6 8 9 11 12
Example1 (For Different Arrival Time)
Process Arrival Burst Time Completion Turn Around Waiting Response
No Time (AT) (BT) Time (CT) Time (TAT) Time (WT) Time (RT)
P1 0 5 3 1 12 12 7 0
0
P2 1 4 2 11 10 6 1
0
P3 2 2 6 4 2 2
0
P4 4 1 9 5 4 4
0
Example1
• Total Turn Around Time = 31 ms
So, Average Turn Around Time = 31/4 = 7.75 ms
• And, Total Waiting Time = 19 ms
So, Average Waiting Time = 19/4 = 4.75 ms
• And, Total Waiting Time = 7 ms
So, Average Response Time = 7/4 = 1.75 ms
Example2 (For Same Arrival Time)
Process No Arrival Time (AT) Burst Time (BT)
P1 0 7
P2 0 5
P3 0 5
Example1
Quantum = 2
Ready Queue:
P1 P2 P3 P1 P2 P3 P1 P2 P3 P1
T=0
Running Queue:
P1
T=0 2 P2 4 P3 6 P1 8 P2 10 P3 12 P1 14 P2 15 P3 17 P1 18
Example2 (For Same Arrival Time)
Process No Arrival Time Burst Time Completion Turn Around Waiting Time
(AT) (BT) Time (CT) Time (TAT) (WT)
P1 0 7 18 18-0=18 11
P2 0 5 15 15-0=15 10
P3 0 5 17 17-0=17 12
Example2
• Total Turn Around Time = 50 ms
So, Average Turn Around Time = 50/3 = 16.667 ms
• And, Total Waiting Time = 33 ms
So, Average Waiting Time = 33/3 = 11.00 ms
Code Snippet
The Round Robin algorithm is a fair and efficient CPU
scheduling algorithm that provides each process with an
equal time slice, making it ideal for real-time systems.
Conclusion
While Round Robin may not always be the most optimal
choice, it strikes a balance between fairness and efficiency.