0% found this document useful (0 votes)
9 views3 pages

Round Robin Scheduling Lab2 (C)

The document contains a C program that implements the Round Robin Scheduling algorithm for process management. It prompts the user to enter the number of processes, their arrival and burst times, and a time quantum, then calculates and displays the waiting and turnaround times for each process. Finally, it computes and prints the average waiting and turnaround times for all processes.

Uploaded by

gobabix905
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Round Robin Scheduling Lab2 (C)

The document contains a C program that implements the Round Robin Scheduling algorithm for process management. It prompts the user to enter the number of processes, their arrival and burst times, and a time quantum, then calculates and displays the waiting and turnaround times for each process. Finally, it computes and prints the average waiting and turnaround times for all processes.

Uploaded by

gobabix905
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

3) Round Robin Scheduling algorithm:

#include <stdio.h>

int main() {

int count,j,n,time,remain,flag=0,time_quantum;

int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];

printf("Enter total number of processes:");

scanf("%d",&n);

remain=n;

for(count=0;count<n;count++)

printf("\n Enter process Arrival time and Burst time for process number %d:\n",count+1);

scanf("%d",&at[count]);

scanf("%d",&bt[count]);

rt[count]=bt[count];

printf("Enter time quantum:\t");

scanf("%d",&time_quantum);

printf("\n Process\twaiting time\tTurnaround time\n\n");

for(time=0,count=0;remain!=0;)

if(rt[count]<=time_quantum&& rt[count]>0)

time+=rt[count];

rt[count]=0;

flag=1;

}
else if(rt[count]>0)

rt[count]-=time_quantum;

time+=time_quantum;

if(rt[count]==0 && flag==1)

remain--;

printf("p[%d]\t\t\t%d\t\t\t%d\n",count+1,time-at[count],time-at[count]-bt[count]);

wait_time+=time-at[count]-bt[count];

turnaround_time+=time-at[count];

flag=0;

if(count==n-1)

count=0;

else if(at[count+1]<=time)

count++;

else

count=0;

printf("\n\n Averege waiting time:%f\n",wait_time*1.0/n);

printf("\n Average turnaround time:%f",turnaround_time*1.0/n);

return 0;

}
Output:

Enter total number of processes:

Enter process Arrival time and Burst time for process number 1:

4 5

Enter process Arrival time and Burst time for process number 2:

2 8

Enter process Arrival time and Burst time for process number 3:

6 4

Enter process Arrival time and Burst time for process number 4:

1 2

Enter process Arrival time and Burst time for process number 5:

0 7

Enter time quantum: 2

Process waiting time Turnaround time

p[4] 11 9

p[1] 11 6

p[3] 13 9

p[2] 21 13

p[5] 26 19

Averege waiting time:11.200000

Average turnaround time:16.400000

=== Code Execution Successful ===

You might also like