Experiment 4
Experiment 4
Experiment 4
a) Round Robin :
#include<stdio.h>
void main ()
ct[i] = bu[i];
max = bu[0];
max = bu[i];
if (bu[i] != 0)
if (bu[i] <= t)
bu[i] = 0;
}
else
bu[i] = bu[i] - t;
temp = temp + t;
att += tat[i];
awt += wa[i];
OUTPUT :
1 21 11 32
2 3 5 8
3 6 15 21
4 2 13 15
FCFS CPU SCHEDULING ALGORITHM
#include<stdio.h>
#include<conio.h>
main()
clrscr();
scanf("%d", &n);
for(i=0;i<n;i++)
scanf("%d", &bt[i]);
wt[0] = wtavg = 0;
for(i=1;i<n;i++)
for(i=0;i<n;i++)
getch();
}
INPUT
OUTPUT
P0 24 0 24
P1 3 24 27
P2 3 27 30
#include<stdio.h>
#include<conio.h>
main()
clrscr();
scanf("%d", &n);
for(i=0;i<n;i++)
p[i]=i;
scanf("%d", &bt[i]);
for(i=0;i<n;i++)
for(k=i+1;k<n;k++)
if(bt[i]>bt[k])
temp=bt[i];
bt[i]=bt[k];
bt[k]=temp;
temp=p[i];
p[i]=p[k];
p[k]=temp;
wt[0] = wtavg = 0;
for(i=1;i<n;i++)
for(i=0;i<n;i++)
printf("\n\t P%d \t\t %d \t\t %d \t\t %d", p[i], bt[i], wt[i], tat[i]);
getch();
INPUT
P3 3 0 3
P0 6 3 9
P2 7 9 16
P1 8 16 24
#include<stdio.h>
main()
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
p[i] = 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++)
for(i=0;i<n;i++)
getch();
INPUT
OUTPUT
42516
0 3 10 6 16
2 4 2 16 18
3 5 1 18 19