C Program To Implement Round Robin Scheduling Algorithm
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 process 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 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 Round Robin Algorithm, every process gets 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.