What is Round Robin Scheduling in OS?

Learn via video courses
Topics Covered

Overview

Round robin is usually the first scheduling algorithm you actually get to code, instead of just drawing arrows on a whiteboard. Below is a complete C program for round robin scheduling, the exact input and output it produces, and a full hand trace so you can check your own logic against it line by line. If you want the theory side first, our piece on round robin scheduling in OS covers where it sits among other algorithms. This page stays close to the code itself: what it prints, why the waiting time numbers land where they do, and how the time quantum you pick changes everything downstream.

What is Round Robin Scheduling in OS?

Round robin is a preemptive CPU scheduling algorithm. Every process gets a fixed slice of CPU time, called the time quantum, before it's paused and pushed to the back of the ready queue. Nobody skips the line, nobody starves. That's the whole pitch. Once a process's slice runs out, it hands the CPU over even if it isn't done, that's preemption, and it's the one thing that separates round robin from something like FCFS, where whoever gets there first just camps on the CPU.

In this algorithm, every process gets executed cyclically. This means that processes that have their burst time remaining after the expiration of the time quantum are sent back to the ready state and wait for their next turn to complete the execution until it terminates. This processing is done in FIFO order which suggests that processes are executed on a first-come, first-serve basis.

Note: The CPU time quantum is the time period defined in the system.

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Algorithm of Round Robin Scheduling in C

● Read the burst time for each process. This program assumes all processes arrive at time 0.

● Read the time quantum.

● Keep a remaining[] array, initialised to each process's burst time.

● Loop while any process still has remaining time: for each process in turn, run it for min(quantum, remaining).

● Subtract that slice from remaining. If it hits zero, record the completion time and mark the process done.

● Once every process is done, compute turnaround time (completion − arrival) and waiting time (turnaround − burst) for each.

● Average both across all processes.

Characteristics of Round Robin Scheduling

● Preemptive by design, so fairness is baked in rather than bolted on.

● No starvation. Every process gets the CPU eventually, no matter how late it joined the queue.

● Performance is quantum-dependent, more than almost any other scheduler on this list.

● Response time is bounded: a process waits at most (n − 1) × quantum for its first turn on the CPU. With 4 processes and a quantum of 2, that's a maximum wait of 6 time units before anyone even gets a second look.

● Average waiting time is usually worse than SJF, but the trade-off is fairness, which SJF doesn't really care about.

How does the Round Robin Algorithm Work?

  1. All the processes are added to the ready queue.
  2. At first, The burst time of every process is compared to the time quantum of the CPU.
  3. If the burst time of the process is less than or equal to the time quantum in the round-robin scheduling algorithm, the process is executed to its burst time.
  4. If the burst time of the process is greater than the time quantum, the process is executed up to the time quantum (TQ).
  5. When the time quantum expires, it checks if the process is executed completely or not.
  6. On completion, the process terminates. Otherwise, it goes back again to the ready state.

Consider the below flow diagram for a better understanding of Round Robin scheduling algorithm:

working of round robin scheduling in os

Characteristics of Round Robin Scheduling in OS

  • Round robin scheduling in os is clock-driven (Hybrid model).
  • It is a Preemptive type of CPU scheduling algorithm in OS.
  • The round-robin algorithm generally focuses on the Time Sharing technique.
  • Round robin Scheduling is the simplest and one of the oldest algorithms.
  • This algorithm is a real-time algorithm as it responds to an event within a specific time limit.
  • Round robin is a widely used algorithm in traditional OS.
Sharpen Your Fundamentals with Free Learning

Example of Round Robin Scheduling Algorithm

Consider the following 6 processes: P1, P2, P3, P4, P5, and P6 with their arrival time and burst time as given below:

Q. What are the average waiting and turnaround times for the round-robin scheduling algorithm (RR) with a time quantum of 4 units?

Process IDArrival TimeBurst Time
P105
P216
P323
P431
P545
P664

Ready Queue:

At first, In the ready queue, process P1 will be executed for a time slice of 4 units. Since there are no processes initially, Process P1, with a burst time of 5 units, will be the only process in the ready queue.

P1
5

How Scaler Transformed Careers in Different Fields

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Ready Queue:

Along with the execution of P1, four more processes, P2, P3, P4, and P5, arrive in the ready queue. P1 will be added to the ready queue due to the remaining 1 unit.

P2P3P4P5P1
63151

Ready Queue:

During the execution of P2, P6 arrived in the ready queue. Since P2 has not been completed, P2 will be added to the ready queue.

P3P4P5P1P6P2
315142

Ready Queue:

Similarly, P3 and P4 have been completed, but P5 has a remaining burst time of 1 unit. Hence it will be added back to the queue.

P1P6P2P5
1421

Ready Queue:

The next processes, P6 and P2, will be executed. Only P5 will be left with 1 unit of burst time.

P5
1

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

GANTT Chart:

The Gantt chart will look like this:

Example of round-robin scheduling algorithm

As we know,

Turn Around Time = Completion Time - Arrival Time
Waiting Time = Turn Around Time - Burst Time

ProcessesArrival Time(AT)Burst Time(BT)Turn Around Time(TAT)Waiting Time(WT)
P1051712
P2162216
P32396
P43198
P5452015
P6641511

Avg Waiting Time = (11+5+8+6+16+12)/6 = 68/6 = 11.33 units.

Implementation of Round Robin Algorithm in C++

Output:

Average Turn Around Time = 15.33 Average Waiting Time = 11.33

  • Code Explanation:
    • Initialize a FIFO queue to implement this algorithm and push the first process into the queue.
    • We will use an array to check whether the process is in the queue.
    • Keep track of the time using a variable - current_time
    • If the process gets CPU for the first time, record its start time as current_time.
    • Give the quantum unit of time to the process in the front of the queue and pop this process from the queue.
    • If the burst time of this process becomes 0, calculate the Completion Time, Turn Around Time, and Waiting Time for it.
    • If some process had arrived when this process was executing, insert them into the queue.
    • If the current process has burst time remaining, push the process into the queue again.
    • If the queue is empty, pick the first process from the list that is not completed.
    • Keep doing this till all processes are completed.

Advantages and Disadvantages of Round Robin Scheduling

Advantages:

● Fair by construction, every process gets a turn, no exceptions

● No starvation, ever, regardless of how many processes are competing

● Works well for time-sharing and interactive systems where responsiveness matters more than raw throughput

Disadvantages:

● Average waiting time is usually higher than SJF for the same workload

● Performance is entirely dependent on picking a sane quantum, get it wrong and you either thrash on switching or drift toward FCFS

Speaking of FCFS, it's worth comparing directly against our FCFS scheduling program in C, especially around the convoy effect, which is the exact problem round robin's preemption exists to solve.

Applications of Round Robin Scheduling

Round robin, or some tuned variant of it, shows up all over real CPU scheduling algorithms in OS, not just in textbook diagrams:

● Time-sharing operating systems, where multiple users or processes need to feel like they each have the CPU to themselves

● Network packet scheduling, cycling fairly through queued packets from different sources

● Multilevel feedback queues, where round robin runs inside one level while priority handles movement between levels

If you want to see how this plays out in a production kernel rather than a 90-line program, the Linux sched(7) man page documents SCHED_RR directly.

You've now implemented and hand-traced a preemptive CPU scheduler from scratch, which is a decent chunk of an operating systems course covered in one sitting. If you want that kind of understanding across the rest of CS fundamentals, with actual mentors checking your work instead of just a compiler, Scaler Academy builds structured programs around exactly that.

FAQs

What is the time quantum in round robin scheduling?

It's the fixed maximum amount of CPU time a process gets before being preempted and sent to the back of the ready queue. Real systems typically use 10 to 100 milliseconds. In the worked example on this page, it's 2 time units.

Is round robin preemptive or non-preemptive?

Preemptive. A running process gets forced off the CPU the moment its quantum expires, whether or not it's finished, and rejoins the queue at the back. That's exactly what guarantees no process starves.

How do you calculate average waiting time in round robin scheduling?

Turnaround time is completion time minus arrival time. Waiting time is turnaround time minus burst time. Average the waiting times across every process. In the worked example: (7 + 7 + 4 + 6) / 4 = 6.00.

What happens if the time quantum is too large or too small?

Too large and it behaves like FCFS, nothing gets preempted once the quantum matches or beats the longest burst. Too small and the CPU burns a real, measurable chunk of its time on context switches instead of actual work.

How do you write a program to implement round robin CPU scheduling?

Keep a burst-time array and a parallel remaining-time array. Loop through processes repeatedly, running each for min(quantum, remaining) and advancing a running clock. Record completion time when remaining hits zero, then derive turnaround and waiting time from that.

Can round robin scheduling be written in C++ or Java?

Yes, the logic doesn't change, only the I/O syntax does. The array-sweep approach here ports over directly, and in C++ or Java a Queue or LinkedList tends to replace the manual sweep once arrival times start differing.

Conclusion

  • The name of this algorithm comes from the round-robin principle, where every person gets an equal share of something turn by turn.
  • Every process gets executed cyclically, and the processing is done in FIFO order.
  • The execution of the Round Robin scheduling algorithm mainly depends on the value of the time quantum.
  • As the time quantum value decreases
    • The response time decreases.
    • And, The number of context switches increases.
  • As the time quantum value increases
    • The response time increases.
    • And, The number of context switches decreases.
  • We can conclude that a good scheduling algorithm for a real-time and time-sharing system must possess the following characteristics:
    • Minimum context switches.
    • Maximum CPU utilization.