Mohd monis choudhary 2023-310-163
Operating Systems Lab: Assignment 3
Learning Objective: To understand how to implement Round Robin CPU Scheduling
Algorithm.
Task: Write a C program to simulate Round Robin CPU scheduling algorithm with (Time
Quantum = 3) to find average waiting time for the below problem:
Process Burst Time
P0 24
P1 3
P2 3
Program Input: Number of Processes, Burst Time for each process and Time Quantum.
Program Output: Average Waiting Time
Code : #include <stdio.h>
void findWaitingTime(int processes[], int n, int bt[], int wt[], int quantum) {
int rem_bt[n];
for (int i = 0; i < n; i++)
rem_bt[i] = bt[i];
int t = 0;
while (1) {
int done = 1;
for (int i = 0; i < n; i++) {
if (rem_bt[i] > 0) {
done = 0;
if (rem_bt[i] > quantum) {
t += quantum;
rem_bt[i] -= quantum;
} else {
Mohd monis choudhary 2023-310-163
t += rem_bt[i];
wt[i] = t - bt[i];
rem_bt[i] = 0;
if (done) break;
void findTurnaroundTime(int processes[], int n, int bt[], int wt[], int tat[]) {
for (int i = 0; i < n; i++)
tat[i] = bt[i] + wt[i];
void findAverageTime(int processes[], int n, int bt[], int quantum) {
int wt[n], tat[n];
findWaitingTime(processes, n, bt, wt, quantum);
findTurnaroundTime(processes, n, bt, wt, tat);
int total_wt = 0, total_tat = 0;
printf("Process\tBurst Time\tWaiting Time\tTurnaround Time\n");
for (int i = 0; i < n; i++) {
total_wt += wt[i];
total_tat += tat[i];
printf("P%d\t\t%d\t\t%d\t\t%d\n", i, bt[i], wt[i], tat[i]);
printf("\nAverage Waiting Time = %.2f", (float)total_wt / n);
printf("\nAverage Turnaround Time = %.2f\n", (float)total_tat / n);
Mohd monis choudhary 2023-310-163
int main() {
int processes[] = {0, 1, 2};
int n = sizeof(processes) / sizeof(processes[0]);
int burst_time[] = {24, 3, 3};
int quantum = 3;
findAverageTime(processes, n, burst_time, quantum);
return 0;
Output :