Round Robin
Round Robin
Round Robin
#include<stdio.h>
main()
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&bu[i]);
ct[i]=bu[i];
scanf("%d",&t);
max=bu[0];
for(i=1;i<n;i++)
if(max<bu[i])
max=bu[i];
for(j=0;j<(max/t)+1;j++)
for(i=0;i<n;i++)
if(bu[i]!=0)
if(bu[i]<=t)
tat[i]=temp+bu[i];
temp=temp+bu[i];
bu[i]=0;
Else
bu[i]=bu[i]-t;
temp=temp+t;
}
for(i=0;i<n;i++)
wa[i]=tat[i]-ct[i];
att+=tat[i];
awt+=wa[i];}
for(i=0;i<n;i++)
getch();
INPUT:
Enter Burst Time for process 1 – 24 Enter Burst Time for process 2 -- 3 Enter Burst Time for process 3 – 3 Enter
the size of time slice – 3
OUTPUT:
1 24 6 30
2 3 4 7
3 3 7 10
The Average Turnaround time is – 15.666667 The Average Waiting time is 5.666667
A). PRIORITY:
DESCRIPTION:
To calculate the average waiting time in the priority algorithm, sort the burst times according to their priorities and
then calculate the average waiting time of the processes. The waiting time of each process is obtained by
summing up the burst times of all the previous processes.
ALGORITHM:
Step 3: For each process in the ready Q, assign the process id and accept the CPU burst time
Step 5: Set the waiting of the first process as ‗0‘ and its burst time as its turnaround time Step 6: Arrange the
processes based on process priority
Step 9: Calculate
d) Average Turnaround time = Total Turnaround Time / Number of process Print the results in an
order.
Step10: Stop
SOURCE CODE:
#include<stdio.h>
main()
clrscr();
for(i=0;i<n;i++)
p[i] = i;
printf("Enter the Burst Time & Priority of Process %d --- ",i); scanf("%d
%d",&bt[i], &pri[i]);
for(i=0;i<n;i++) for(k=i+1;k<n;k++)
temp=p[i];
p[i]=p[k];
p[k]=temp;
temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;
temp=pri[i];
pri[i]=pri[k];
pri[k]=temp;
wtavg =wt[0] = 0;
for(i=1;i<n;i++)
{
wt[i] = wt[i-1] + bt[i-1];
for(i=0;i<n;i++)
getch();
INPUT
1 1 1
4 2 5 1 6
0 3 10 6 16
2 4 2 16 18
3 5 1 18 19