0% found this document useful (0 votes)
18 views4 pages

Round Robin Scheduling

Uploaded by

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

Round Robin Scheduling

Uploaded by

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

ROUND ROBIN SCHEDULING & PRIORITY SCHEDULING ALGORITHM

PROGRAM

Round Robin Scheduling

#include<stdio.h>
#include<conio.h>

void main() { int n,


i, j, quantum; int
bt[10], rt[10]; int
wt[10], tat[10];
int avg_wt, avg_tat;

printf("Enter number of processes: ");


scanf("%d", &n);

("Enter burst time for each process:\n");


for(i =0; i < n;i++)
{ printf("Process %d: ",i+1);
scanf("%d", &bt[i]);
rt[i] = bt[i];
}

printf("Enter time quantum: ");


scanf("%d", &quantum);

int total = 0; while(total ! =


n ){ for(i = 0 i ; i < n ;i++)
{ if(rt[i] > 0)
{ if(rt[i] <= quantum)
{ total++;
wt[i]-total-bt[i];
tat[i]=wt[i]+bt[i];
rt[i] = 0;
} else
{ rt[i]=quantu
m;
}
}
}
}

avg_wt=0; avg
tat=0; for(i=0;
i<n; i++)
{ avg_wt +=
wt[i];
avg_tat += tat[i];
}

avg_wt /=n; avg_tat


/=n; printf("\
nProcess\tBurst
Time\tWaiting
Time\tTurnaround
Time\n"); for(i=0;
i<n; i++) {
printf("%d\t%d\t\t%d\t\t%d\n", i+1, bt[i], wt[i], tat[i]);
}

printf("\nAverage Waiting Time: %.2f\n", (float)avg_wt);


printf("Average Turnaround Time: %.2f\n", (float)avg_tat);
}

OUTPUT:

Enter number of processes: 3

Enter burst time for each process:

Process 1:10

Process 2:5

Process 3: 8

Enter time quantum: 4

Process Burst Time Waiting Time Turnaround Time

1 10 12 22

2 5 0 5
3 8 14 22

Average Waiting Time: 8.00

Average Turnaround Time: 16.33


b. Priority Scheduling

#include<stdio.h>
#include<conio.h>

void main() {
int n, i, j;
int bt[10], p[10], wt[10], tat[10];
int avg_wt, avg_tat;

printf("Enter number of processes: ");


scanf("%d", &n);

printf("Enter burst time and priority for each process: \n");


for(i=0; i<n; i++) {
printf("Process %d: Burst Time: ", i+1);
scanf("%d", &bt[i]); printf("Priority: ");
scanf("%d", &p[i]);

// Sorting processes based on priority


for( i = 0; i < n ;i++) { for(j=i+1; j<n;
j++) { if(p[t] < p[i]) { int
temp=bt[i]; bt[i] = bt[j];
bt[j]=temp;

temp = p[i];
p[i] = p[i];
p[j] = temp;
}
}
}

wt[0] = 0;
tat[0] = bt[0];

for(i=1;i<n; i++) { wt[i] =


wt[i - 1] + bt[i - 1];
tat[i]=wt[i]+bt[i];
}
avg_wt = 0;
avg_tat=0;
for(i=0; i < n; i++)
{ avg_wt += wt[i];
avg_tat += tat[i];
}

avg_wt/= n;
avg_tat /= n;

printf("\nProcess\tBurst Time\tPriority\tWaiting Time\tTurnaround Time\n");


for(i=0; i<n; i++) {
printf("%d\t%d\t\t%d\t\t%d\t\t%d\n", i+1, bt[i], p[i], wt[i], tat[i]);
}

printf("\nAverage Waiting Time: %.2f\n", (float)avg_wt); printf("Average


Turnaround Time: %.2f\n", (float)avg_tat); }

OUTPUT:

Enter number of processes: 3

Enter burst time and priority for each process:

Process 1: Burst Time: 8

Priority: 2

Process 2: Burst Time: 4

Priority: 1

Process 3: Burst Time: 6

Priority: 3

Process Burst Time Priority Waiting Time Turnaround Time

1 8 2 0 8
2 4 1 8 12
3 6 3 12 18
Average Waiting Time: 6.67

Average Turnaround Time: 12.67

You might also like