Let us learn how to implement round robin scheduling algorithm in C programming with its explanation, output, advantages, disadvantages and much more.
What is Round Robin Scheduling Algorithm?
The round robin algorithm is a pre-emptive process scheduling algorithm. In this algorithm, every job request in the queue is associated with a fixed execution time called as quantum.
A pre-emptive process enables the job scheduler to pause a process under execution and move to the next process in the job queue.
Once a particular process/job is executed for a given time quantum, the job scheduler saves the current state of the job and moves to another job in the queue.
The current state of the process is saved by a process called as a context switch. This algorithm is beneficial in terms of its response time.
In 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.
The round robin job scheduling algorithm is used in a multi-user, time-sharing or multi-tasking operating systems. It is probably the best scheduling algorithm in operating systems for distributed terminal response time.
The efficiency of this algorithm is totally dependent on the size of the time quantum and number of context switches that occur.
- The decision making overhead is very low.
- Every job within the queue is given an equal amount of priority, unlike other scheduling algorithms.
- Starvation does not occur so frequently.
- The throughput in round-robin algorithm is highly dependent on the quantum length.
- If the quantum is less, then the process switching occurs frequently which decreases the efficiency.
- If the quantum is more, the system may become unresponsive.
Note: This round robin scheduling C program is compiled with GNU GCC compiler using Linux terminal on Linux Ubuntu operating system.
C Program For Round Robin Scheduling Algorithm
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 doubts about the implementation of round robin scheduling algorithm in C programming, let us know about it in the comment section. Find more about it on Wikipedia.