C Program To Implement Round Robin Scheduling Algorithm
Let us learn how to implement Round Robin scheduling algorithm in C programming language. The RR scheduling algorithm is a disk scheduling algorithm for tasks or processes that are needed to be executed. The round robin algorithm is normally represented using Gantt’s Chart on paper.
The round robin scheduling program in C language is normally implemented in operating systems to schedule multiple processes entering the CPU for execution. This code is for round robin non – preemptive algorithm in C programming.
What is Round Robin Scheduling Algorithm?
The round robin program is used in a multi-user time-sharing or multi-tasking operating systems. This algorithm is used where response time is an important factor.
The decision making overhead in RR algorithm is very low. It is probably the best scheduling algorithm in OS for distributed terminal response time.
Therefore, every process gets uniformly distributed execution time. In a round robin algorithm, every process gets an equal time of execution which is defined by the quantum time. Therefore, no process will be able to hold the CPU for a longer time period.
This round robin program is a preemptive algorithm which means one process under execution can be left in between and another process can be executed.
The process that was left midway is saved with its current state and when the CPU executes that process again from its waiting queue, it resumes from the same state.
There is a disadvantage with the round robin non-preemptive scheduling program. The waiting time of the processes and, therefore, the average waiting time of the processes will increase.
A long process will need to wait for more time in the waiting queue whereas the short burst time process will need to wait for a less time. Therefore, both the long and short processes will suffer in this algorithm.
C Program For Round Robin Scheduling Algorithm with Arrival Time
int i, limit, total = 0, x, counter = 0, time_quantum;
int wait_time = 0, turnaround_time = 0, arrival_time, burst_time, temp;
float average_wait_time, average_turnaround_time;
printf("\nEnter Total Number of Processes:\t");
x = limit;
for(i = 0; i < limit; i++)
printf("\nEnter Details of Process[%d]\n", i + 1);
temp[i] = burst_time[i];
printf("\nEnter Time Quantum:\t");
printf("\nProcess ID\t\tBurst Time\t Turnaround Time\t Waiting Time\n");
for(total = 0, i = 0; x != 0;)
if(temp[i] <= time_quantum && temp[i] > 0)
total = total + temp[i];
temp[i] = 0;
counter = 1;
else if(temp[i] > 0)
temp[i] = temp[i] - time_quantum;
total = total + time_quantum;
if(temp[i] == 0 && counter == 1)
printf("\nProcess[%d]\t\t%d\t\t %d\t\t\t %d", i + 1, burst_time[i], total - arrival_time[i], total - arrival_time[i] - burst_time[i]);
wait_time = wait_time + total - arrival_time[i] - burst_time[i];
turnaround_time = turnaround_time + total - arrival_time[i];
counter = 0;
if(i == limit - 1)
i = 0;
else if(arrival_time[i + 1] <= total)
i = 0;
average_wait_time = wait_time * 1.0 / limit;
average_turnaround_time = turnaround_time * 1.0 / limit;
printf("\n\nAverage Waiting Time:\t%f", average_wait_time);
printf("\nAvg Turnaround Time:\t%f\n", average_turnaround_time);
If you have any compilation errors or doubts in this C Program to implement round robin scheduling algorithm with explanation and arrival time, let us know about in the comment section below. Find more about round robin algorithm on Wikipedia.