Os Lab
Os Lab
OBJECTIVE
Program to perform FIFO page replacement algorithm.
PROGRAM LOGIC
PROGRAM
#include<stdio.h>
void main()
{
int i,j,n,k,m,r,pagef;
int a[100],b[100];
k=0,pagef=0;
printf("enter the number of pages\n");
scanf("%d",&n);
printf("enter the number of frames in main memory\n");
scanf("%d",&m);
for(i=0;i<m;i++)
b[i]=-1;
for(i=0;i<n;i++)
{
printf("enter the element %d\n",i);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(b[j]==a[i])
{
printf("the page %d is already present in main memory\n",a[i]);
break;
}
}
if(j==m)
{
b[k]=a[i];
k++;
if(k==m)
k=0;
for(r=0;r<m;r++)
printf("%d ",b[r]);
printf("\n");
pagef++;
}
}
printf("number of page faults: %d",pagef);
}
INPUT AND OUTPUT
7 -1 -1
7 0 -1
7 0 1
2 0 1
the page 0 is already present in main memory
2 0 3
the page 0 is already present in main memory
4 0 3
4 0 2
4 3 2
0 3 2
the page 3 is already present in main memory
the page 2 is already present in main memory
1 3 2
the page 2 is already present in main memory
1 0 2
the page 1 is already present in main memory
1 0 7
the page 0 is already present in main memory
the page 1 is already present in main memory
number of page faults: 12
b) LRU
OBJECTIVE
PROGRAM LOGIC
7 -1 -1
7 0 -1
7 0 1
2 0 1
the page 0 is already present in main memory
2 0 3
the page 0 is already present in main memory
4 0 3
4 0 2
4 3 2
0 3 2
1 3 2
1 0 2
1 0 7
a)Sequential
a)Sequential
OBJECTIVE
Program to perform SEQUENTIAL file allocation technique
PROGRAM LOGIC
Step 3: Get the number of processes and values of block size for each process.
Step 4: First fit algorithm searches all the entire memory block until a hole which is big enough is
encountered. It
Step 5: Best-fit algorithm searches the memory blocks for the smallest hole which can be allocated
to requesting process
Step 6: Worst fit algorithm searches the memory blocks for the largest hole and allocates it to the
process.
Step 7: Analyses all the three memory management techniques and display the best algorithm which
utilizes the
PROGRAM
#include<stdio.h>
void main()
int a[100],s[10],l[10],n,m,c,i,j,k;
scanf("%d",&m);
scanf("%d",&n);
for(i=0;i<=m;i++)
a[i]=-1;
for(i=0;i<n;i++)
{
scanf("%d",&s[i]);
scanf("%d",&l[i]);
for(i=0;i<n;i++)
for(k=s[i],j=0;j<l[i];j++,k++)
if(a[k]==-1)
c=0;
else
c=1;
break;
if(c==1)
if(c==0)
for(k=s[i],j=0;j<l[i];j++,k++)
a[k]=i;
}
}
14
19
28
OBJECTIVE
PROGRAM LOGIC
PROGRAM
#include<stdio.h> #include<conio.h> void
main()
{
int gd=DETECT,gm,count,i,j,mid,cir_x;
char fname[10][20];
clrscr();
initgraph(&gd,&gm,"c:\\tc\\bgi");
cleardevice();
setbkcolor(GREEN);
puts("Enter no of files do u
have?");
scanf("%d",&count);
for(i=0;i<count;i++)
{
clear
devi
ce();
setb
kcol
or(G
REE
N);
printf("Enter file %d
name",i+1);
scanf("%s",fname[i]);
setfillstyle(1,MAGENTA);
mid=640/count;
cir_x=mid/3;
bar3d(270,100,370,150,0,0);
settextstyle(2,0,4);
settextjustify(1,1);
outtextxy(320,125,"Root
Directory"); setcolor(BLUE);
for(j=0;j<=i;j++,cir_x+=mid)
{
line(320,150,
cir_x,250);
fillellipse(cir_
x,250,30,30);
outtextxy(cir_
x,250,fname[j
]);
}
getch();
}
}