4.0: Literature Review: Round Robin CPU Scheduling Algorithm
4.0: Literature Review: Round Robin CPU Scheduling Algorithm
0: RATIONALE: Round Robin (RR) scheduling algorithm is widely used scheduling algorithm in
multitasking. It ensures fairness and starvation free execution of processes. Choosing the time
quantum in RR is very crucial as small time slice results in large number of context switches and large
time quantum increases the response time. Experimental analysis reveals that the proposed
algorithm produces better average turnaround time, average waiting time and fewer number of
context switches than existing algorithms.
2.0: AIM OF MICRO PROJECT: To develop a program in ‘C’ demonstrating the Round Robin
Scheduling Algorithm.
3.0: COURSE OUTCOMES ACHIEVED: A. Install operating system and configure it. B. Use operating
system tools to perform various functions. C. Execute process commands for performing process
management operations. D. Apply scheduling algorithms to calculate turnaround time and average
waiting time.
Step 2: Now, we push the first process from the ready queue to execute its task for a
fixed time, allocated by each process that arrives in the queue.
Step 3: If the process cannot complete their task within defined time interval or slots
because it is stopped by another process that pushes from the ready queue to
execute their task due to arrival time of the next process is reached. Therefore, CPU
saved the previous state of the process, which helps to resume from the point where
it is interrupted. (If the burst time of the process is left, push the process end of the
ready queue).
Step 4: Similarly, the scheduler selects another process from the ready queue to
execute its tasks. When a process finishes its task within time slots, the process will
not go for further execution because the process's burst time is finished.
Step 5: Similarly, we repeat all the steps to execute the process until the work has
finished.
1. It is a pre-emptive algorithm.
2. It shares an equal time interval between all processes to complete their task.
3. It is a starvation free CPU scheduling algorithm. Hence it is known as the
fairest and simple algorithm.
Advantages
Disadvantage
1. If the time quantum is lower, it takes more time on context switching between
the processes.
2. It does not provide any special priority to execute the most important process.
3. The waiting time of a large process is higher due to the short time slot.
4. The performance of the algorithm depends on the time quantum.
5. The response time of the process is higher due to large slices to time
quantum.
6. Getting a correct time slot or quantum is quite difficult for all processes in the
round-robin algorithm.
P1 0 8
P2 5 2
P3 1 7
P4 6 3
P5 8 5
Now we have to create the ready queue and the Gantt chart for Round Robin CPU
Scheduler.
Ready queue: P1, P3, P1, P2, P4, P3, P5, P1, P3, P5
Step 1: At time 0, process P1 enters the ready queue and starts its execution for the
defined time slot 3. During 3 units of the time slice, another process, P3, arrives in the
ready queue because its arrival time is 1.
Step 2: Now, process P3 starts its execution with a time slot of 3 units while process
P1 has to wait. After execution of process P3, process P1 again resumes its execution
for time slot 3.
Step 3: During the execution of process P1, two more processes P2 and P4, arrive in
the ready queue to begin their execution. Since process P2 has come first, it will be
executed for time quantum 2 units after that P4 is executed.
Step 4: Here, P4 has executed for time slot 3 units, and its task is completed because
BT (Burst Time) is 2. Hence it will not go to the ready queue.
Step 5: After that, process P3 is executed from the ready queue for time slot 3 and
then process P5 arrives for time slot 3.
Step 7: Now process P1 is fetched from the ready queue and starts their execution
for time slot 2 as it requires only 2 BT to finish its tasks. Hence it will not go to the
ready queue for further execution.
Step 8: Now, the process P3 is executed for time slot 1 as it requires only 1 BT to
complete its tasks.
Step 9: The final process P5 is executed for time slot 2 because it requires only 2 BT
to complete its tasks.
The following are the important terms to find the Completion time, Turn Around
Time (TAT), Response Time (RT) and Waiting Time (WT).
P1 0 8 22 22 14
P2 5 2 11 6 4
P3 1 7 23 22 15
P4 6 3 14 8 5
P5 8 5 25 17 12
Turn Around Time for P1 = Completion Time (CT) - Arrival Time (AT)
22 - 0 = 22
Turn Around Time for P2 = 11 - 5 = 6
Turn Around Time for P3 = 23 - 1 = 22
Turn Around Time for P4 = 14 - 6 = 8
Turn Around Time for P5 = 25 - 8 = 17
Waiting Time for P1 = Turn Around Time (TAT) - Burst Time (BT)
22 - 8 = 14
Waiting Time for P2 = 6 - 2 = 4
Waiting Time for P3 = 22 - 7 = 15
Waiting Time for P4 = 8 - 3 = 5
Waiting Time for P5 = 17 - 5 = 1
P1 0 8
P2 1 5
P3 2 10
P4 3 11
Step 2: Now, process P2 starts their execution for time slot 5 units because the Burst
Time (BT) is 5, and it does not go to the ready queue for further execution.
Step 3: After that process, P3 will start its execution, which has 10 Burst time, but the
time quantum is 6 units. Therefore, it executes its tasks for a defined time limit and is
added to the ready queue's end.
Step 4: After that, the process P4 starts their execution, which has burst time 11, but
the time quantum is 6 units. It executes its tasks for only 6 seconds and then adds to
the end of the ready queue.
Step 5: After the execution of P4, now P1 will start its execution again for 2 units or
second, and the process P1 terminate or end. Similarly, the complete execution of
process P1, then P3, starts its remaining execution for Burst Time 4, and the process
is completed.
Step 6: After the complete execution of process P3, now process P4 executes for the
remaining time slot, which is 5, and the process is finished.
Process Arrival Time Burst Time Completion Time Turn Around Time
P1 0 8 25 25
P2 1 5 11 10
P3 2 10 29 27
P4 3 11 34 31
Now we find the completion, Turn around time, waiting time and the
average TAT and waiting time.
P1 = 25-8 =17
P2 = 10-5 =5
P3 = 27-10= 17
P4 = 31-11=20
Average Waiting Time is: (17+5+17+20)/4 = 59/4 = 14.75
The Round Robin (RR) scheduling algorithm is designed especially for time sharing systems. RR is
the pre-emptive process scheduling algorithm.
Round robin scheduling is the pre-emptive version of First Come First Serve (FCFS) scheduling.
Processes are dispatched in First In First Out (FIFO) sequence but each process is allowed to run for
only a limited amount of time.
It is similar to FCFS scheduling but pre-emption is added to switch between processes. A small unit
of time called a Time Quantum or Time Slice is defined.
A time quantum is generally from 10 to 100 milliseconds. The ready queue is treated as a circular
queue. The CPU scheduler goes around the ready queue, allocating CPU to each process for a time
interval of up to 1 time quantum.
In RR scheduling process are dispatched FIFO but are given a limited amount of processor time
called a time slice or time quantum.
If a process does not complete before its quantum expires, the system preempts it and gives the
processor to the next waiting process. The system then places the preempted process at the back of
the ready queue.
In the fig. process P1 is dispatched to a processor, where it executes either until completion, in
which case it exits the system, or until its time slice expires, at which point is pre-empted and placed
at the tail of the ready queue. The scheduler then dispatches process P2. Dispatch Round Robin
Scheduling
To implement RR scheduling we keep ready queue as FIFO queue of processes. New processes are
added to the tail of the ready queue. The average waiting time under the RR policy however is often
quite long. Example of round robin scheduling algorithm: Assume there are 5 processes with process
ID and burst time given below PID Burst Time P1 6 P2 5 P3 2 P4 3 P5 7
Time quantum
Assume that all process arrives at 0. Now, we will calculate average waiting time for these
processes to complete. Solution: We can represent execution of above processes using GANTT chart
as shown below – Round Robin Example Gantt Chart – 1 Explanation: First p1 process is picked
from the ready queue and executes for 2 per unit time (time slice = 2). If arrival time is not available,
it behaves like FCFS with time slice. After P2 is executed for 2 per unit time, P3 is picked up from
the ready queue. Since P3 burst time is 2 so it will finish the process execution at once. D CPU A B C
Preemption Timeout Completed Job Like P1 & P2 process execution, P4 and p5 will execute 2 time
slices and then again it will start from P1 same as above. Waiting time = Turn Around Time – Burst
Time P1 = 19 – 6 = 13 P2 = 20 – 5 = 15 P3 = 6 – 2 = 4 P4 = 15 – 3 = 12 P5 = 23 – 7 = 16 Average waiting
time = (13+15+4+12+16) / 5 = 12.
Flowchart
: C program code:
1. https://en.wikipedia.org/wiki/Round-robin_scheduling. 2.
https://www.irjet.net/archives/V3/i3/IRJET-V3I3285.pdf. 3.
https://www.thecrazyprogrammer.com/2015/09/round-robin-scheduling-program-inc.html.
8.0: SKILLS DEVELOPED: From this we learnt about CPU scheduling in operating system. Also, we
got to know about finding average waiting time and average turnaround time each process
executing in operating system. Round Robin scheduling is an algorithm mainly used by operating
systems and applications that serve multiple clients that request to use resources. 9.0:
APPLICATIONS OF MICRO PROJECT: This can be used as reference for people who want to learn
Round Robin Algorithm. This algorithm dramatically improves average response time. By limiting
each task to a certain amount of time, the operating system can ensure that it can cycle through all
ready tasks, giving each one a chance to run.