Operating System Lab
Operating System Lab
NO TITLE Page no
A4 PRIORITY 10-12
for(i=0;i<n;i++)
printf("\tP%d\t\t%d\t\t%d\t\t%d\n",i,bt[i],wt[i],tat[i]);
printf("\n Average Waiting Time --%f",wtavg/n);
printf("\n Average turnaround Time --%f",tatavg/n);
getch();
}
FCFS ScreenShot
4
temp=p[i];
p[i]=p[k];
p[k]=temp;
}
wt[0]=wtavg=0;
tat[0]=tatavg=bt[0];
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+bt[i-1];
tat[i]=tat[i-1]+bt[i];
wtavg=wtavg+wt[i];
tatavg=tatavg=tat[i];
}
printf("\n\tPROCEESS\tBURST TIME \tWAITING TIME \t TURNARROUND TIME\n");
for(i=0;i<n;i++)
printf("\n\tP%d\t\t%d\t\t%d\t\t%d",p[i],bt[i],wt[i],tat[i]);
}printf("\nAverage waiting Time--%f",wtavg);
printf(\nAverage Turnarround Time-- %f"tatavg/n);
getch();
}
6
SJF Screenshot
7
}
b[smallest]--;
if(b[smallest]==0)
{
count++;
end=time+1;
avg=avg+end-a[smallest]-x[smallest];
tt= tt+end-a[smallest];
}
}
printf("\n\nAverage waiting time = %lf\n",avg/n);
printf("Average Turnaround time = %lf",tt/n);
return 0;
}
9
SRTF ScreenShot
10
A3: Priority
#include<stdio.h>
void main()
{
int p[20],bt[20],pri[20],wt[20],tat[20],i,k,n,temp;
float wtavg,tatavg;
clrscr();
printf("enter the number of process--");
scanf("%d",&n);
for(i=0;i<n;i++)
{
p[i]=i;
printf("enter the burst time and priorty of Proces %d--",i);
scanf("%d%d",&bt[i],&pri[i]);
}
for(k=i+1;k<n;k++)
if(pri[i]>pri[k])
{
temp=p[i];
p[i]=p[k];
p[k]=temp;
temp=p[i];
bt[i]=bt[k];
bt[k]=temp;
11
temp=pri[i];
pri[i]=pri[k];
pri[k]=temp;
}
wtavg=wt[0]=0;
tatavg=tat[0]=bt[0];
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+b[i-1];
tat[i]=tat[i-1]+bt[i];
wtavg=wtavg+wt[i];
tatavg=tatavg+tat[i];
}
printf("\nProcess\tPriorty\t Burst time\t Waiting Time \t Turnaround Time");
for(i=0;i<n;i++)
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",p[i],pri[i],bt[i],wt[i],tat[i]);
printf("\nAverage Waitng Time is -%f",wtavg/n);
printf("\n Average Turnaround Time is --%f",tatavg/n);
getch();
}
12
PRIORITY ScreenShot
13
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];
}
printf("\n The Avrage Turnaround time is --%f",att/n);
printf("\n The Average waiting time is --%f ",awt/n);
printf("\n\tPROCESS\t\tBURST TIME\t WAITING TIME\tTURNARUND TIME \n");
for(i=0;i<n;i++)
printf("\t%d\t\t%d\t\t%d\t\t%d\n",i+1,ct[i],wa[i],tat[i]);
getch();
}
15
RoundRobin ScreenShot:
16
}
if(k==f)
{
m[count++]=rs[i];
pf++;
}
for(j=0;j<f;j++)
printf("\t%d",m[j]);
if(k==f)
printf("\tPF NO %d",pf);
printf("\n");
if(count==f)
count=0;
}
printf("\n The number of page fault FIFO are %d",pf);
getch();}
18
FIFO ScreeenShot:
19
{
for(j=0;j<f;j++)
{
if(m[j]==rs[i])
{
flag[i]=1;
count[j]=next;
next++;
}}
if(flag[i]==0)
{
if(i<f)
{
m[i]=rs[i];
count[i]=next;
next++;
}
else
{
min=0;
for(j=1;j<f;j++)
if(count[min]>count[j])
min=j;
m[min]=rs[i];
21
count[min]=next;
next++;
}
pf++;
}
for(j=0;j<f;j++)
printf("%d\t",m[j]);
if(flag[i]==0)
printf("PF NO-- %d",pf);
printf("\n");
}
printf("\n The number of page fault using LRU are %d",pf);
getch();
}
22
break;
}
rempages=rempages-s[i];
printf("Enter pagetable for[%d]--",i);
for(j=0;j<s[i];j++)
scanf("%d",&fno[i][j]);
}
printf("\n Enter Logical Addresss to find pysical Address");
printf("\n Enter process no and pagenumber and offset--");
scanf("%d%d%d",&x,&y,&offset);
if (x>np||y>=s[i]||offset>=ps)
printf("\n In valid proceess or page number or offset ");
else
{
pa=fno[x][y]*ps+offset;
printf("\n the physical address is %d",pa);
}
getch();
}
25
ScreenShot
26