Published: 7 Nov 2025 | Reading Time: 6 min read
Imagine you're waiting for your turn on a carnival ride. Everyone in line gets a fixed amount of time on the ride. When your turn ends, you go back to the end of the line if you want to try again.
That's exactly how Round Robin Scheduling works in operating systems.
If you are a CS student, preparing for OS / DSA interviews, or learning CPU scheduling, the Round Robin program in C is one of the most frequently asked concepts, both theoretically and in coding assignments. Understanding it helps you:
In the next few minutes, you'll learn:
By the end, you will be able to write and explain the Round Robin program in C confidently, perfect for exams, projects, and interviews.
Round Robin (RR) scheduling is one of the most widely used CPU scheduling algorithms developed to allocate CPU time to each process in a round-robin way. Round Robin scheduling is cyclic in nature and is also known as Time Slicing Scheduling. Each process is allotted a fixed time slice or quantum. If the process does not finish the execution of its work within the time assigned, it is placed at the end of the ready queue, and the CPU scheduler will pick up the next process. In this way, every process is treated more or less fairly; all processes will be given equal amounts of CPU time in a round-robin manner.
Here are the characteristics of round robin scheduling:
FCFS stands for the First Come First Serve method for CPU scheduling; it runs processes in the order in which they come to the queue. The process that arrives first gets executed first, and the process that arrives next will have to wait, and so on. One of the simplest CPU scheduling algorithms, FCFS scheduling generally consists of a FIFO (First In First Out) queue.
Here are the characteristics of FCFS scheduling:
Both Round Robin (RR) and FCFS (First Come First Serve) are CPU scheduling algorithms used in operating systems, but they differ in how they allocate CPU time and handle running processes.
| Feature / Criteria | FCFS Scheduling (First Come First Serve) | Round Robin Scheduling |
|---|---|---|
| Scheduling Type | FCFS is a non-preemptive scheduling algorithm, where a process runs until it finishes. | Round Robin is a preemptive scheduling algorithm, where processes are interrupted and resumed based on time slices. |
| Execution Order | Processes are executed strictly in the order they arrive in the ready queue. | Every process gets CPU time in a cyclic order, one after another. |
| Time Quantum / Time Slice | There is no concept of time quantum; the CPU runs a process until completion. | Uses a fixed time quantum (time slice) such as 2ms or 4ms for each process. |
| Responsiveness | Responsiveness is low because long processes can delay shorter ones, causing the convoy effect. | Responsiveness is high because processes frequently get CPU time, ideal for interactive systems. |
| Fairness | FCFS is not always fair; long-running tasks can block short tasks. | Round Robin ensures fairness by giving equal CPU time to every process. |
| Starvation Possibility | Starvation is possible if shorter jobs wait behind long ones. | There is no starvation; every process gets CPU access in turns. |
| Context Switching | Minimal context switching since processes are not interrupted. | Frequent context switching due to time slicing. |
| Best Used In | Best suited for batch processing systems where simplicity matters more than responsiveness. | Best suited for time-sharing and multitasking systems like modern operating systems. |
| Waiting Time | Waiting time can be high, especially for shorter processes stuck behind longer ones. | Waiting time is generally lower because every process gets CPU time repeatedly. |
| Complexity | Very simple to understand and implement. | Slightly more complex because it handles time quantum and multiple context switches. |
In short, Round Robin focuses on responsiveness and equal CPU access, whereas FCFS prioritizes simplicity and sequential execution.
This C program executes based on a Round Robin algorithm that gives a constant time quantum to each process in the ready queue. The essence of operation is that each process can expect an equitable time of CPU in a rotated fashion, disallowing any one process from taking over the CPU to the exclusion of all others, thus ensuring starvation-free operation of the system.
The Round Robin CPU Scheduling algorithm allocates a fixed amount of processing time to a job before it is forced to wait its turn again. Each process gets a chance to execute for one time unit (as defined here), depending on the time section al-zampa, and upon the expiration of its time quantum, it is sent back to the end of the queue. This is repeated until all processes finish executing.
Let's assume:
In this step, the Gantt chart illustrates the order in which processes execute.
| Time | Process |
|---|---|
| 0-1 | P1 |
| 1-2 | P2 |
| 2-3 | P3 |
| 3-4 | P4 |
| 4-5 | P1 |
| 5-6 | P2 |
| 6-7 | P3 |
| 7-8 | P4 |
| 8-9 | P1 |
| 9-10 | P2 |
| 10-11 | P4 |
| 11-12 | P2 |
| 12-13 | P4 |
| 13-14 | P2 |
To obtain the waiting time for each process, we need to know when it finished firing and how long it waited while other job arrivals were being executed. Thus, the waiting time can be calculated as:
Waiting time = Turnaround time − Burst time
As a reminder, Turnaround time is the total time from arrival to completion.
Now let's look at the waiting times for each process:
The average waiting time is the sum of the individual waiting times divided by the number of processes:
Average waiting time = (6 + 10 + 5 + 9) / 4 = 30 / 4 = 7.5 units
If we assume the quantum time to be 2ms, that means that each process has 2ms maximum to execute. If the process is not done after 2ms, it simply goes to the back of the queue for their next turn.
| Cycle | Time Interval | Process Executing | Remaining Burst Time for A | Remaining Burst Time for B | Remaining Burst Time for C |
|---|---|---|---|---|---|
| 1 | 0-2 ms | A | 4 ms | 6 ms | - |
| 2-4 ms | B | 4 ms | 2 ms | - | |
| 4-6 ms | C | 4 ms | 2 ms | 6 ms | |
| 2 | 6-8 ms | A | 2 ms | 2 ms | 6 ms |
| 8-10 ms | B | 2 ms | 0 ms | 6 ms | |
| 10-12 ms | C | 2 ms | 0 ms | 4 ms | |
| 3 | 12-14 ms | A | 0 ms | 0 ms | 4 ms |
| 14-16 ms | C | 0 ms | 0 ms | 2 ms | |
| 4 | 16-18 ms | C | 0 ms | 0 ms | 0 ms |
Execution Summary:
Let's look at some terminology before entering the algorithm:
Step 1: Input processes: Gathering process details, including burst time, arrival time and process ID.
Step 2: Sort processes: Arranging processes based on their arrival time.
Step 3: Allocation of time quantum: Each task is assigned a fixed time quantum for execution.
Step 4: Execute processes: All tasks are executed for a time quantum or until the task is completed and either removed from the queue (if finished) or moved to the back of the queue till its next turn.
Step 5: Repeat steps: Continue the cycle till all tasks are executed.
In a sequential arrival time, each process comes to the CPU one after the other, increasing the process arrival time within a unit interval(i.e., 1 or any other constant). Hence, in this case, all processes were sequentially arriving at the CPU and were scheduled using the Round Robin algorithm.
Here is an example of sequential arrival time:
#include <stdio.h>
void main() {
int i, processes, sum = 0, cnt = 0, y, q, wt = 0, tat = 0, at[10], bt[10], temp[10];
float avg_waitt, avg_turnat;
// Input the number of processes
printf("Total number of processes in the system: ");
scanf("%d", &processes);
y = processes; // Assign number of processes to y
// Input arrival time and burst time for each process
for(i = 0; i < processes; i++) {
printf("\nEnter the Arrival and Burst time of Process[%d]\n", i + 1);
printf("Arrival time: ");
scanf("%d", &at[i]);
printf("Burst time: ");
scanf("%d", &bt[i]);
temp[i] = bt[i]; // Initialize remaining burst time
}
// Input the time quantum
printf("Enter the Time Quantum: ");
scanf("%d", &q);
// Display header for the process info
printf("\nProcess No \tBurst Time \tTAT \t\tWaiting Time\n");
// Scheduling loop
for(sum = 0, i = 0; y != 0;) {
if(temp[i] <= q && temp[i] > 0) {
sum = sum + temp[i];
temp[i] = 0;
cnt = 1;
} else if(temp[i] > 0) {
temp[i] = temp[i] - q;
sum = sum + q;
}
if(temp[i] == 0 && cnt == 1) {
y--; // Decrement remaining processes
printf("\nProcess No[%d] \t%d \t\t%d \t\t%d", i + 1, bt[i], sum - at[i], sum - at[i] - bt[i]);
wt = wt + sum - at[i] - bt[i]; // Calculate waiting time
tat = tat + sum - at[i]; // Calculate turnaround time
cnt = 0;
}
if(i == processes - 1) {
i = 0;
} else if(at[i + 1] <= sum) {
i++;
} else {
i = 0;
}
}
// Calculate average waiting time and turnaround time
avg_waitt = wt * 1.0 / processes;
avg_turnat = tat * 1.0 / processes;
printf("\nAverage Turnaround Time: %f", avg_turnat);
printf("\nAverage Waiting Time: %f", avg_waitt);
}
This program implements the Round Robin scheduling algorithm. It receives the number of processes, their arrival and burst times as inputs. Then, once the waiting time, turnaround time, and averages for all processes are calculated, the CPU time is allocated to each process in the time slices of the fixed time quantum.
//Input
Total number of processes in the system: 3
Enter the Arrival and Burst time of Process[1]
Arrival time: 0
Burst time: 5
Enter the Arrival and Burst time of Process[2]
Arrival time: 1
Burst time: 3
Enter the Arrival and Burst time of Process[3]
Arrival time: 2
Burst time: 4
Enter the Time Quantum: 3
//output
Process No Burst Time TAT Waiting Time
Process No[1] 5 8 3
Process No[2] 3 6 3
Process No[3] 4 7 3
Average Turnaround Time: 7.000000
Average Waiting Time: 3.000000
Complexity Analysis:
Round Robin provides equitable CPU time access for every process, which make it particularly suitable for multitasking systems. Due to its cyclic execution and fixed time quantum, it is guaranteed that no process will be starved and the system will remain responsive. If you want to truly understand how RR works, implement the C program for round robin scheduling, coding it once, which clarifies everything better than theory.
CPU scheduling with zero arrival time is a situation in which all the processes arrive at 0. The scheduler does not discriminate between arrival times; all these processes are available to the CPU at the same point in time, thus making it focus only on the burst times (execution times) of the processes.
Step 1: Initialize the processes with the parameters timeQuantum, current_time, waiting_time, turnaround_time, completed_processes.
Step 2: While fewer than the total number of processes have been completed:
For any process:
Step 3: Average waiting time and turnaround time calculated and printed.
#include <stdio.h>
#define MAX 10 // Maximum number of processes
// Structure to hold process details
struct Process {
int id; // Process ID
int burstTime; // Burst Time
int remainingTime; // Remaining Time
};
// Function to implement Round Robin scheduling
void roundRobin(struct Process processes[], int n, int timeQuantum) {
int time = 0; // Tracks current time
int completed = 0;
int waitingTime = 0, turnaroundTime = 0;
// Array to track the remaining time of each process
while (completed < n) {
for (int i = 0; i < n; i++) {
// If process still has remaining time
if (processes[i].remainingTime > 0) {
if (processes[i].remainingTime > timeQuantum) {
processes[i].remainingTime -= timeQuantum;
time += timeQuantum;
} else {
time += processes[i].remainingTime;
waitingTime += time - processes[i].burstTime;
turnaroundTime += time;
processes[i].remainingTime = 0;
completed++;
}
}
}
}
printf("\nAverage Waiting Time = %.2f\n", (float)waitingTime / n);
printf("Average Turnaround Time = %.2f\n", (float)turnaroundTime / n);
}
// Main function
int main() {
struct Process processes[MAX];
int n, timeQuantum;
printf("Enter the number of processes: ");
scanf("%d", &n);
// Input processes burst times
for (int i = 0; i < n; i++) {
processes[i].id = i + 1;
printf("Enter burst time for process %d: ", i + 1);
scanf("%d", &processes[i].burstTime);
processes[i].remainingTime = processes[i].burstTime; // Initialize remaining time
}
printf("Enter time quantum: ");
scanf("%d", &timeQuantum);
// Run Round Robin Scheduling
roundRobin(processes, n, timeQuantum);
return 0;
}
This above code uses a simulation of Round Robin scheduling by assigning a fixed quantum time for every process. It proceeds in cycles along the processes, executing each in cycles, updating burst times, and then calculating waiting and turnaround times for all processes until completion.
Enter the number of processes: 3
Enter burst time for process 1: 10
Enter burst time for process 2: 5
Enter burst time for process 3: 8
Enter time quantum: 4
Average Waiting Time = 6.33
Average Turnaround Time = 13.33
Complexity Analysis:
In Round Robin (RR) scheduling, each process is cyclically assigned a fixed time quantum (or time slice). When there are different arrival times for the processes, the scheduler must consider the arrival time of each process before scheduling it. Round Robin with different arrival times works as follows:
Step 1: Initialize processes with timeQuantum, current_time, waiting_time, turnaround_time, completed_processes.
Step 2: While not all processes are completed:
Step 3: For each process:
Step 4: Calculate and print average waiting_time and turnaround_time.
#include <stdio.h>
#define MAX 10 // Maximum number of processes
// Structure to hold process details
struct Process {
int id; // Process ID
int arrivalTime; // Arrival Time
int burstTime; // Burst Time
int remainingTime; // Remaining Time
int waitingTime; // Waiting Time
int turnaroundTime; // Turnaround Time
};
// Function to implement Round Robin scheduling
void roundRobin(struct Process processes[], int n, int timeQuantum) {
int currentTime = 0; // Tracks current time
int completed = 0;
float totalWaitingTime = 0, totalTurnaroundTime = 0;
while (completed < n) {
for (int i = 0; i < n; i++) {
if (processes[i].arrivalTime <= currentTime && processes[i].remainingTime > 0) {
if (processes[i].remainingTime > timeQuantum) {
processes[i].remainingTime -= timeQuantum;
currentTime += timeQuantum;
} else {
currentTime += processes[i].remainingTime;
processes[i].waitingTime = currentTime - processes[i].arrivalTime - processes[i].burstTime;
processes[i].turnaroundTime = currentTime - processes[i].arrivalTime;
totalWaitingTime += processes[i].waitingTime;
totalTurnaroundTime += processes[i].turnaroundTime;
processes[i].remainingTime = 0;
completed++;
}
}
}
}
// Display results
printf("\nProcess ID | Arrival Time | Burst Time | Waiting Time | Turnaround Time\n");
for (int i = 0; i < n; i++) {
printf("%9d | %12d | %10d | %12d | %15d\n", processes[i].id, processes[i].arrivalTime,
processes[i].burstTime, processes[i].waitingTime, processes[i].turnaroundTime);
}
// Calculate averages
printf("\nAverage Waiting Time = %.2f\n", totalWaitingTime / n);
printf("Average Turnaround Time = %.2f\n", totalTurnaroundTime / n);
}
// Main function
int main() {
struct Process processes[MAX];
int n, timeQuantum;
// Input number of processes
printf("Enter the number of processes: ");
scanf("%d", &n);
// Input processes' arrival times and burst times
for (int i = 0; i < n; i++) {
processes[i].id = i + 1;
printf("Enter arrival time and burst time for process %d: ", i + 1);
scanf("%d %d", &processes[i].arrivalTime, &processes[i].burstTime);
processes[i].remainingTime = processes[i].burstTime; // Initialize remaining time
}
// Input time quantum
printf("Enter time quantum: ");
scanf("%d", &timeQuantum);
// Run Round Robin Scheduling
roundRobin(processes, n, timeQuantum);
return 0;
}
In the above example, the round robin scheduling with varying arrival times allocates CPU time in fixed time slices that cycle through the set of processes. Processes can start as per their arrival time, and if they don't complete in the quantum time frame, then they are suspended or preempted and get placed back in the queue. The process of CPU execution continues until all processes are executed.
//Input
Enter the number of processes: 3
Enter arrival time and burst time for process 1: 0 10
Enter arrival time and burst time for process 2: 1 5
Enter arrival time and burst time for process 3: 2 8
Enter time quantum: 4
//Output
Process ID | Arrival Time | Burst Time | Waiting Time | Turnaround Time
1 | 0 | 10 | 6 | 16
2 | 1 | 5 | 4 | 9
3 | 2 | 8 | 4 | 12
Average Waiting Time = 4.67
Average Turnaround Time = 12.33
Complexity Analysis:
1. Handles Different Arrival Times:
Dynamically checks processes to see if they have arrived at each time step.
2. Idle CPU Handling:
Increments currentTime if no process i.e. no process is ready to simulate the CPU waiting for a new process to be ready to execute.
3. Fair Scheduling:
Distributes CPU time equally among all processes using round-robin scheduling.
4. Process Preemption:
Processes may be preempted (stopped) once their time quantum has expired and placed at the back of the queue.
5. Cyclic Execution:
Processes can execute in the queue continuously until termination.
6. Starvation-Free:
A starvation-free approach that guarantees the processes are provided CPU time.
7. Efficiency Considerations:
As the time quantum gets shorter, the number of context switches begins to increase the overhead to a point that can outweigh the beneficial usability.
Round Robin scheduling continues to have extensive use in multiple computing settings, owing to its fairness, simplicity, and cyclic execution as shown in the examples below:
Round Robin is typically the scheduling algorithm used in time-sharing systems; this is when multiple users/processes are sharing CPU resources. By giving processes a time quantum, it ensures that there are quick context switches and fairness, allowing all users to experience responsive computing.
In interactive systems, such as graphical user interfaces, word processors, or terminal sessions, Round Robin scheduling keeps the user interface responsive. Each process in the ready queue gets a regular opportunity to use the CPU, preventing any single task from freezing the system.
Servers adopting a Round Robin would be those handling multiple client requests (Web servers and application servers) to ensure that processes can be serviced fairly. The advantage of the Round Robin algorithm is the avoidance of client starvation and equality of resource sharing.
Routers, switches, and other networking equipment commonly implement Round Robin in their network schedulers to coordinate data packet transmission. The network scheduler will cycle through each packet or flow and grant the fair use of the network shared bandwidth, effectively stopping a single connection from monopolizing the network.
Operating systems also incorporate Round Robin into their process schedulers when managing processes from the ready queue. In a multitasking environment, this is a suitable and convenient way to allow processes to share time on the CPU, as each process is always guaranteed access to the CPU in a given or defined cycle.
Round Robin is not the most practical scheduling algorithm choice for all real-time systems due to the fact that it does not allow for process priorities. However, in soft real-time systems, Round Robin can be used since fairness is valued more than the time predictability requirements. For hard real-time tasks, it is preferred that specialized schedulers be used.
Educational institutions, research labs, and shared computing clusters frequently run Round Robin style scheduling, as users need the ability to run programs concurrently on the same CPU without any one program entirely monopolizing the CPU.
Round Robin scheduling is a widely used CPU scheduling algorithm, especially in time-sharing and multitasking systems. Understanding its advantages and limitations is important for anyone studying operating systems or preparing to implement this algorithm in C.
Round Robin is a starvation-free algorithm. Each process is guaranteed a fair opportunity to access and use the CPU such that a single process cannot simply be ignored or indefinitely wait.
Round Robin is characterized by its cyclical nature, which ensures that each process is executed in rotating order. Therefore, it is easy to describe, understand and implement this expected scheduling.
Fixing a time quantum (or time slice) for each process allows the system to respond quickly to interacting processes. This obviously fits well with time-sharing environments and is important for the user experience.
The algorithm is very simple, especially when coded using basic data structures such as simple queues.
The system switches contexts often, allowing processes to run in parallel so that progress is being made on multiple processes in tandem. Thus, the system appears multitasked / responsive.
If the quantum is too small, much of the CPU's time in context switching rather than running the process which contributes to the efficiency of the system.
Choosing the right time quantum is challenging.
Processes that may get a long burst may experience long waits before completing, as they are given their time, get preempted, and then cycle through the queue again for execution.
Since processes are treated equally, Round Robin is not recommended within a system that has microprocesses / systems that have certain priorities or deadlines for some tasks.
The algorithm does not consider process importance, which may not be suitable when some tasks are more critical than others.
Design a struct to hold each process's essential attributes: process ID, arrival time, burst time, remaining time, waiting time, and turnaround time. This makes your code organized and helps in tracking each process's state throughout the scheduling.
Always check for valid input values such as positive burst times, non-negative arrival times, and a sensible time quantum (not zero or negative). Input validation prevents logical errors and unexpected behavior during execution.
Implement the ready queue using an array or linked list to efficiently cycle through processes. A proper queue ensures that preempted processes are placed at the end, maintaining the cyclic nature of Round Robin scheduling.
Accurately update the current time after each process's time slice or completion. Make sure context switching is reflected in the simulation, and the scheduler advances time correctly, especially when new processes arrive or the CPU becomes idle.
Maintain variables to track waiting time and turnaround time for each process. After scheduling, compute and display average waiting time and average turnaround time, as these metrics are crucial for evaluating scheduling efficiency.
Test your implementation with a variety of input cases: all processes arriving at time zero, staggered arrival times, varying burst times, and different time quantum values. This ensures your program handles edge cases and behaves as expected in real-world scenarios.
These best practices will help you write robust, efficient, and easy-to-understand Round Robin scheduling programs in C, making your code ready for academic assignments, interviews, or real-world applications.
Round Robin stands out as one of the fairest and responsive CPU scheduling algorithms, especially for time-sharing and multitasking systems. It cycles through each process's sequential order with a time slice for the process, eliminating monopolization of CPU resources and allowing a smoother, efficient process switch time.
Why it matters: Recognizing the rationale of round robin scheduling algorithms in C helps students to understand how actual operating systems control simultaneous multiple processes in a timely manner.
If you want to master this concept, don't just read; try building a round robin program in C. Once you simulate time quanta, waiting time, and turnaround time in code, the core idea becomes crystal clear.
Round Robin(RR) is a preemptive CPU scheduling algorithm that assigns a fixed time quantum to each process. After the quantum expires, the process is preempted and placed at the back of the queue, allowing other methods to work on a particular CPU cycle.
Round Robin creates a circular queue at the CPU that contains all processes. Each process has a time quantum that acts like an interval timer; then, the process is sent to the first unfinished process in the queue, ensuring that all processes get a fair share of the CPU time.
Round Robin is a scheduling algorithm emphasising fairness by making every process wait an equal time quantum. Starvation of processes is avoided, as the algorithm is also fair. Round Robin is also a widely accepted way of sharing time, in which all processes are treated equally.
The inefficiency of Round Robin scheduling occurs in those processes characterised by high-caliber limits. When a long-running process is transacted with other running processes, an inordinate number of context switches are made that incur overhead. With a small time quantum, there would be excessive switching, causing performance to plummet.
Round Robin cannot be given the right credit to offer a service to real-time systems, since it does not treat the procedures according to their deadline. Real-time systems use scheduling wherein RMS can be treated with great robustness, as this scheduling relates to timing constraints and the urgency of the tasks.
Round Robin process scheduling in C is the algorithm implementation required to manage the processes in a queue and assign a fixed time slice to each. Once a process's time slice runs out, it is placed at the end of the queue.
A common example involves a set of processes, each with specified arrival and burst times, scheduled using the Round Robin CPU scheduling policy. The goal is to determine the order of execution, average waiting time, and average turnaround time using a given time quantum.
In Round Robin scheduling, you simulate the execution in cycles, updating each process's remaining burst time and tracking when each process finishes.
Example:
Suppose you have three processes:
With all processes arriving at time 0 and a time quantum of 2 units.
Solution Steps:
The time quantum determines how long each process can run before being preempted. A small time quantum increases context switching but improves responsiveness, while a large time quantum reduces context switching but may delay shorter tasks.
Source: NxtWave - https://www.ccbp.in/blog/articles/round-robin-program-in-c