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

RR

Uploaded by

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

RR

Uploaded by

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

#include <stdio.

h>

int main() {
int i, j, n, q, complete = 0, t = 0;
int bt[10], wt[10], tat[10], at[10], rem_time[10];
int sum_tat = 0, sum_wt = 0;
int avg_tat, avg_wt;

//printf("Round Robin Scheduling Algorithm\n");


printf("Enter the total number of processes: ");
scanf("%d", &n);

printf("Enter the burst times of the processes:\n");


for (i = 0; i < n; i++) {
//printf("Burst time for process %d: ", i + 1);
scanf("%d", &bt[i]);
rem_time[i] = bt[i]; // Initialize remaining time
}

printf("Enter the arrival times of the processes:\n");


for (i = 0; i < n; i++) {
//printf("Arrival time for process %d: ", i + 1);
scanf("%d", &at[i]);
}

printf("Enter the time quantum: ");


scanf("%d", &q);

// Print the process details


printf("\n-----------------------------------------------------------\n");
printf("Processes\tArrival Time\tBurst Time");
printf("\n-----------------------------------------------------------\n");
for (i = 0; i < n; i++) {
printf("P[%d]:\t\t %d\t\t %d\n", i + 1, at[i], bt[i]);
}
printf("\n-----------------------------------------------------------\n");

// Round Robin Scheduling


while (complete < n) {
for (i = 0; i < n; i++) {
if (at[i] <= t && rem_time[i] > 0) {
if (rem_time[i] > q) {
t += q;
rem_time[i] -= q;
} else {
t += rem_time[i];
wt[i] = t - bt[i] - at[i];
tat[i] = bt[i] + wt[i];
sum_tat += tat[i];
sum_wt += wt[i];
rem_time[i] = 0;
complete++;
}
}
}
t++; // Increment time to ensure forward progress if no processes can run
}

// Print the results


printf("\
n----------------------------------------------------------------------------------
-\n");
printf("Processes\tArrival Time\tBurst Time\tWaiting Time\tTurnaround Time");
printf("\
n----------------------------------------------------------------------------------
-\n");
for (i = 0; i < n; i++) {
printf("P[%d]:\t\t %d\t\t %d\t\t %d\t\t %d\n", i + 1,
at[i], bt[i], wt[i], tat[i]);
}
printf("\
n----------------------------------------------------------------------------------
-\n\n");

// Calculate and print average turnaround time and waiting time


for(i=0;i<n;i++)
{
sum_tat = sum_tat + tat[i];
}
avg_tat = sum_tat / n;
printf("The average turnaround time for the processes is: %d\n\n", avg_tat);

for(i=0;i<n;i++)
{
sum_wt = sum_wt + wt[i];
}
avg_wt = sum_wt / n;

printf("The average waiting time for the processes is: %d\n", avg_wt);

return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy