×

Operating System Tutorial

Operating System Practice

Round Robin Scheduling Algorithm in Operating System

In this tutorial, we will learn about the round-robin scheduling algorithm in an operating system with the help of an example. By Monika Sharma Last updated : May 07, 2023

What is Round Robin Scheduling Algorithm in OS?

Round Robin scheduling algorithm is a type of preemptive type of scheduling used by the operating system for scheduling the processes. In the Round Robin scheduling algorithm, a time quantum is decided which remains constant throughout the execution of all processes. Each process executes only for this much time. If within this time, the process completes its execution, then it is terminated. Else, it waits for its turn for again getting the processor for the same time quantum, and this process continues. Let us understand it further with the help of an example.

Round Robin Scheduling Algorithm Example

Suppose we have 4 processes: P1, P2, P3, and P4, with the following properties:

Round Robin Scheduling in OS (1)

And suppose that the time quantum decided is 2 units. So, the execution of these processes while following the Round Robin Scheduling will be as follows:

Gant Chart

Round Robin Scheduling in OS (2)

Explanation

  • P1 runs for 2 units from 0 to 2, and now it needs the 1-time unit more for completion.
  • P2 runs from 2 to 4 and it also now it also needs only a one-time unit more for completion.
  • P3 runs from 4-6 and within this time quantum itself, it has been completed.
  • Now, P4 runs from 6 to 8 and now it needs 2-time units more.
  • Now, P1 is again provided the processor for 2-time units as per the decided time quantum, but its execution completes in 1-time unit itself. So, without any delay, the subsequent process is executed.
  • Same as P1, P2 also gets completed in 1-time unit itself.
  • Then P4 is provided the processor and it completes its execution.
Round Robin Scheduling in OS (3)
Total Turn-Around Time = 9 + 9 + 3 + 7
            = 28 milliseconds
Average Turn-Around Time= Total Turn-Around Time / Total No. of Processes
            = 28 / 4
            = 7 milliseconds

Total Waiting Time = 6 + 6 + 1 + 3
            = 16 milliseconds
Average Waiting Time = Total Waiting Time / Total No. of Processes
            = 16 / 4
            = 4 milliseconds



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.