Os lab Manual
Os lab Manual
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int et[20],at[10],n,i,j,temp,p[10],st[10],ft[10],wt[10],ta[10];
int totwt=0,totta=0;
float awt,ata;
char pn[10][10],t[10];
clrscr();
printf("Enter the number of process:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
printf("Enter the name ,arrivaltime,execution time &priority:");
flushall();
scanf("5s%d%d%d",pn[i],&at[i],&et[i],&p[i]);
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(p[i]<p[j])
{
temp=p[i];
p[i]=p[j];
p[j]=temp;
temp=at[i];
at[i]=at[j];
at[j]=temp;
temp=et[i];
et[i]=et[j];
et[j]=temp;
strcpy(t,pn[i]);
strcpy(pn[i],pn[j]);
strcpy(pn[j],t);
}
}
for(i=0;i<n;i++)
{
if(i==0)
{
st[i]=at[i];
wt[i]=st[i]-at[i];
ft[i]=st[i]+et[i];
ta[i]=ft[i]-at[i];
}
else
{
st[i]=ft[i-1];
wt[i]=st[i]-at[i];
ft[i]=st[i]+et[i];
ta[i]=ft[i]-at[i];
}
totwt+=wt[i];
totta+=ta[i];
}
awt=(float)totwt/n;
ata=(float)totta/n;
printf("/n Pname\tarrivaltime\texecution\tpriority\twaitingtime\ttatime");
for(i=0;i<n;i++)
printf("\n%s\t%5d\t%5d\t\t%5d\t\t%5d\t\t5d",pn[i],at[i],et[i],p[i],wt[i],ta[i]);
printf("\nAverage waiting time is:%f",awt);
printf("\nAverage turnaroundtime is:%f",ata);
getch();
}
OUTPUT:
Enter the Number of Processes: 3
Enter the Process Name, Arrival Time & Execution time & priority: 1 2 3 1
Enter the Process Name, Arrival Time & Execution time & priority: 2 4 5 2
Enter the Process Name, Arrival Time & Execution time & priority: 3 5 6 3
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],b[20],n,p=0,q=0,m=0,h,k,i,q1=1;
char f='F';
clrscr();
printf("Enter the Number of pages:");
scanf("%d",&n);
printf("Enter %d page Number:",n);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++)
{
if(p==0)
{
if(q>=3)
q=0;
a[q]=b[i];
q++;
if(q1<3)
{
q1=q;
}
}
printf("\n%d",b[i]);
printf("\t");
for(h=0;h<q1;h++)
printf("%d",a[h]);
if((p==0)&&(q<=3))
{
printf("-->%c",f);
m++;
}
p=0;
for(k=0;k<q1;k++)
{
if(b[i+1]==a[k])
p=1;
}
}
printf("\nNo of faults:%d",m);
getch();
}
OUTPUT:
Enter the No of pages: 12
Enter 12 page Numbers: 2 3 2 1 5 2 4 5 3 2 5 2
2 2-->F
3 23-->F
2 23
1 231-->F
5 531-->F
2 521-->F
4 524 -->F
5 524
3 324 -->F
2 324
5 354 -->F
2 352 -->F
No of faults: 9
LRU
AIM: A Program to Simulate the LRU Page
Replacement Algorithm.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int g=0,a[5],b[20],p=0,q=0,m=0,h,k,I,q1,j,u,n;
char f=’F’;
clrscr();
printf(“Enter the no of pages:”);
scanf(“%d”,&n);
printf(“Enter %d page numbers:”,n);
for(i=0;i<n;i++)
scanf(“%d”,&b[i]);
for(i=0;i<n;i++)
{
if(p==0)
{
if(q>=3)
q=0;
a[q]=b[i];
q++;
if(q1<3)
{
q1=q;
g=1;
} }
printf(“\n%d”,b[i]);
printf(“\t”);
for(h=0;h<q;h++)
printf(“%d”,a[h]);
if((p==0)&&(q<=3))
{
Printf(“-->%c”,f);
m++;
}
p=0;
q=0;
if(q1==3)
{
for(k=0;k<q1;k++)
{
if(b[i+1]==a[k])
p=1;
}
for(j=0;j<q1;j++)
{
u=0;
k=i;
while(k>=(i-1)&&(k>=0))
{
if(b[k]==a[j])
u++;
k--;
}
if(u==0)
q=j;
} }
else
{
for(k=0;k<q;k++)
{
if(b[i+1]==a[k])
p=1;
} } }
printf(“\n No of Faults:%d”,m);
getch();
}
OUTPUT:
No of Faults: 7