1. Home
Operating System

OS Tutorial: Learn Operating Systems Basics

Learn Operating System fundamentals: concepts, processes, memory management, and more. Start your journey to mastering OS with our comprehensive tutorial.

  • 47
  • 7 Hours
right-top-arrow

Tutorial Playlist

47 Lessons
28

Round Robin Scheduling in Operating System

Updated on 19/07/2024446 Views

CPU scheduling ensures timely execution of processes on a computer's CPU, often referred to as the brain of the computer. It determines the order of process execution, allowing one process to use the CPU while others wait. This approach promotes efficiency and ensures smooth system performance.

Round-robin CPU scheduling is the most efficient scheduling algorithm. Mostly used in multitasking systems, this method has helped me run a system for years at its full capacity. Let me explain the process of Round Robin scheduling in OS to help you understand its application altogether. 

Round Robin CPU Scheduling: What It Is 

The Round Robin scheduling algorithm is a process that allotts each task to a fixed period of time quantum to be executed. Time quantum is the time frame for which a task is allowed to run in a pre-emptive technique.

Processes that have remaining burst time after the expiration of their time quantum are returned to the ready state, awaiting their next opportunity for execution. This process, which operates on a first-come-first-serve (FIFO) basis, ensures that all processes are given fair access to the CPU and prevents starvation. It continues until a process terminates.

However, to understand the working of Round Robin algorithm, ensure that you know all about what an operating system is and what it does. 

Features of Round Robin CPU Scheduling

Some features of this OS scheduling are as follows: 

  • The CPU shifts to the next process after a fixed time interval, known as a time slice or time quantum.
  • The pre-empted process is added at the end of the queue. 
  • It is a hybrid clock-driven model. 
  • It is a real-time algorithm, responding to events within the specified time limit. 

Functioning of the Round Robin Scheduling Program 

This scheduling algorithm ensures balanced resource usage to prevent errors and other issues. A real life example of Round Robin scheduling can be seen in offices. Let’s say, you are in a business meeting that uses Round Robin scheduling. In such a setting, every attendee takes turns in presenting their ideas. 

To implement the Round Robin CPU scheduling, processes are placed in a ready queue. Each process has a burst time compared against the CPU's time quantum. If the burst time is equal to or less than the time slice, the process is executed for the burst time. If it exceeds the time slice, it runs until the time slice ends. If not completed, the process returns to a ready state. 

Check out the Round Robin process scheduling algorithm above to understand the process better. 

Advantages of Round Robin Scheduling 

Round-robin is a very old and popularly used CPU scheduling method. Some of its advantages are as follows: 

  • This algorithm offers the best performance in terms of average response time. 
  • Every process is allocated a specific time quantum. 
  • Implementation of Round Robin scheduling algorithm ensures that all the tasks get a fair allocation of the CPU. 
  • Starvation or convoy effect is not an issue. 
  • No particular priority is offered to any process, it is done in a FIFO manner.
     
  • A Round Robin scheduler is present which acts as a warden and employs time slots for every task. 

Disadvantages of Round Robin scheduling 

Some disadvantages of this scheduling algorithm are as follows: 

  • It spends a lot of time on context switches. 
  • This algorithm has time-consuming scheduling for a small quantum. 
  • It has a longer response and waiting time. 
  • You will not be able to set any special priority in this algorithm. 

Optimizing the Performance of a Round Robin Scheduling Algorithm in OS 

Here’s a good Round Robin scheduling example. 

Let’s say, you and I are up against each other in a tennis tournament. With this scheduling method, all the matches in the tournament are allocated time. How you and I perform during that time slice we have, will determine who moves forward and who loses. 

With this, we can say that the Round Robin algorithm performance largely depends on the quantum size. If the quantum size is too small, there will be too many context switches which will waste CPU time. 

On the contrary, if the quantum size is too large, the algorithm will reduce the fairness and responsiveness of the system. Hence, the quantum time should be based on the requirements and characteristics of the tasks and system. 

It should neither be too small nor too large. 

Examples of Round Robin CPU Scheduling Algorithm

Let us check out the Round Robin scheduling algorithm with example: 


Example 1 

There are six processes in a system. Calculate the turn-around times as well as the average waiting time for algorithm having a 3 units time quantum. 

The arrival time and burst time of the processes are given below: 

Process name

Arrival time 

Burst time 

P1 

0

4

P2 

1

5

P3 

2

2

P4 

3

1

P5 

4

4

P6 

5

3

The process P1 is going to be in the queue at first. It is going to be run for time frame 3 units. 

P1 

4

As the first process is being executed, P2, P3, and P4 are added in the queue. At the end of this process, P1 has 1 unit left to be executed, hence it is put in the queue. 

P2 

P3 

P4 

P1 

5

2

1

1

As P2 is being executed, P5 and P6 have arrived at the queue. As P2 is not completely executed, it is put in queue. 

P3 

P4 

P1 

P5 

P6 

P2 

2

1

1

4

3

2

Processes P3 as well as P4 are completed. However, the remaining P5 has burst time left, which is why it is added at the back of the line-up. 

P1 

P6 

P2 

P5 

1

3

2

1

All the processes are executed except P5. it is the only process left with a burst time of 1 unit. 

P5 

1

The GANTT chart of the above process is: 

P1 

P2 

P3 

P4 

P1 

P5 

P6 

P2 

P5 

0             3               6              8               9              10            13            16             18         19

To find out the turn-around time and the waiting time of the above process, we can create the following table. 

Process name

Arrival time 

Burst time 

Turn-around time 

(completion time - arrival time)

Waiting time 

(turn-around time - burst time)

P1 

0

4

10

6

P2 

1

5

17

12

P3 

2

2

6

4

P4 

3

1

6

5

P5 

4

4

15

11

P6 

5

3

11

8

Average waiting time = (6+12+4+5+11+8)/6 = 46/6 = 7.66


Example 2

Calculate Round Robin scheduling and the average waiting time for the processes given below: 

Process name 

Arrival time 

Burst time 

P1 

0

7

P2 

1

4

P3 

2

5

P4 

The time quantum value is 4. 

At first the process P1 is going to be executed. It has a burst time of 7. 

P1 

As the first process is being executed through four units, the remaining processes, P2, P3, and P4 are added to the queue. P1 is not completely executed and hence it is added to the back of the queue. 

P2 

P3 

P4 

P1 

4

5

8

3

P2 is completed in this step, but P3 and P4 are not, which is why it is added to the back of the queue.

P1 

P3 

P4 

3

1

4

All the processes are executed, apart from P4. It is again added to the queue. 

P4 

4

The GANTT chart of this scheduled algorithm is as follows: 

P1 

P2 

P3 

P4 

P1 

P3 

P4 

0                  4                   8                  12                 16                19                 20                24

Process name 

Arrival time 

Burst time 

Turn-around time 

(completion time - arrival time)

Waiting time 

(turn-around time - burst time)

P1 

0

7

19

12

P2 

1

4

7

3

P3 

2

5

18

13

P4 

21

13

Average wait time: (12+3+13+13)/4 = 41/4 = 10.25

Know about the functions of an operating system to understand the implications of Round Robin scheduling algorithm. 

Difference Between Round Robin CPU Scheduling and Shortest Job First Algorithm 

Both of these are scheduling algorithms, however, there are some major differences between them. 

Round Robin 

Shortest Job First

It executes processes depending upon the denied time quantum 

It executes processes depending upon the ascending order of their burst times.

The average waiting time is the minimum for a given set of processes. 

The average waiting time is very small depending upon the time quantum. 

It is difficult to know the length of the next CPU burst or request. 

It is quite easy to implement. 

Long processes might not get executed. The system might only execute the short ones. 

Every process is executed in fixed time intervals. 

Final Words 

The Round Robin scheduling in operating systems stands out for its simplicity and fairness. In my experience, it is a great way of increasing the efficiency of your system. The balanced approach that this process provides, is necessary for multitasking systems. 

The Round Robin CPU scheduling algorithm is needed in many fields. If you want you expand your career, enrolling in a certified course can be a great choice. Check out the courses upGrad is offering. These courses are taught by experienced professionals and will make you ready for the market.  

Frequently Asked Questions    

  1. What is the round robin technique?

In this CPU scheduling method, each process is given a fixed time period, called a quantum, for execution. If the process doesn't finish within this time, it's returned to the scheduling queue for later processing.

  1. What is a round robin example?

In round robin scheduling, processes are executed in a circular manner. For example, process A is executed for a fixed time, followed by process B, and so forth until completion.

  1. What is a round-robin scheduling format?

It's the structure used to implement round robin scheduling, involving maintaining a queue of processes and cycling through them, allocating each a fixed time slice.

  1. Why is it called round robin?

The basis of this principle is that every task is arranged cyclically and all of them are executed turn-by-turn. Hence the name Round Robin. 

  1. What are the advantages of round-robin scheduling?

It provides fair allocation of CPU time among processes, prevents starvation, and ensures responsiveness, especially in time-sharing systems.

  1. Is round-robin scheduling fair?

Round-robing CPU scheduling is one of the most fair OS scheduling methods. Here each process is allocated a fixed amount of time. Once the time expires, the process moves back to the end of the queue. This ensures that every process is executed by the CPU. 

  1. What are the basic features of round-robin scheduling?

Every process is assigned a specific time interval (quantum) for execution. These processes are arranged in a queue, and if a process doesn't complete its task within the allotted time, it's interrupted and returned to the queue.

  1. Why is round robin better than SJF?

Round robin ensures fairness and prevents starvation by giving each process a chance to execute, whereas SJF may lead to longer waiting times for processes with longer burst times, potentially causing starvation for shorter processes.

  1. Which CPU scheduling is best?

The best CPU scheduling algorithm varies depending on the system's requirements. It's not universally optimal for all scenarios and is influenced by factors such as system load, process characteristics, and system goals.

  1. Is Round Robin an algorithm?

Yes, round robin is a CPU scheduling algorithm commonly used in operating systems to allocate CPU time among multiple processes.

Ankit Mittal

Ankit Mittal

Working as an Senior Software Engineer at upGrad, with proven experience across various industries.

Get Free Career Counselling
form image
+91
*
By clicking, I accept theT&Cand
Privacy Policy
image
Join 10M+ Learners & Transform Your Career
Learn on a personalised AI-powered platform that offers best-in-class content, live sessions & mentorship from leading industry experts.
right-top-arrowleft-top-arrow

upGrad Learner Support

Talk to our experts. We’re available 24/7.

text

Indian Nationals

1800 210 2020

text

Foreign Nationals

+918045604032

Disclaimer

upGrad does not grant credit; credits are granted, accepted or transferred at the sole discretion of the relevant educational institution offering the diploma or degree. We advise you to enquire further regarding the suitability of this program for your academic, professional requirements and job prospects before enr...