0% found this document useful (0 votes)
23 views

Os Lab

The document summarizes how to simulate different file organization techniques: 1) It discusses simulating a single level directory by getting the directory name, number of files, and each file name. Each file is represented as a filled circle connected to the directory. 2) It also discusses simulating a two level directory with subdirectories and files within them. 3) A hierarchical directory technique with subdirectories within subdirectories is simulated. 4) A directed acyclic graph (DAG) file organization is also simulated, representing files and directories as nodes connected by edges in a DAG.

Uploaded by

2021cse.rl1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Os Lab

The document summarizes how to simulate different file organization techniques: 1) It discusses simulating a single level directory by getting the directory name, number of files, and each file name. Each file is represented as a filled circle connected to the directory. 2) It also discusses simulating a two level directory with subdirectories and files within them. 3) A hierarchical directory technique with subdirectories within subdirectories is simulated. 4) A directed acyclic graph (DAG) file organization is also simulated, representing files and directories as nodes connected by edges in a DAG.

Uploaded by

2021cse.rl1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

a)FIFO

OBJECTIVE
Program to perform FIFO page replacement algorithm.
PROGRAM LOGIC

Step 1: Create a queue to hold all pages in memory


Step 2: When the page is required replace the page at the head of the queue
Step 3: Now the new page is inserted at the tail of the queue
Step 4: When the page fault occurs replace page present at the head of thequeue
Step 5: Stop the program

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

enter the number of pages 20


enter the number of frames in main memory 3
enter the element 0
7
enter the element 1
0
enter the element 2
1
enter the element 3
2
enter the element 4
0
enter the element 5
3
enter the element 6
0
enter the element 7
4
enter the element 8
2
enter the element 9
3
enter the element 10
0
enter the element 11
3
enter the element 12
2
enter the element 13
1
enter the element 14
2
enter the element 15
0
enter the element 16
1
enter the element 17
7
enter the element 18
0
enter the element 19
1

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 to perform LRU page replacement algorithm

PROGRAM LOGIC

Step 1: Create a queue to hold all pages in memory


Step 2: When the page is required replace the page at the head of the queue
Step 3: Now the new page is inserted at the tail of the queue
Step 4: Create a stack
Step 5: When the page fault occurs replace page present at the bottom of the stack
6.2.3 PROGRAM
#include<stdio.h>
int lrupage(int w[],int m);
void main()
{
int i,j,n,m,r,pagef,l,h,p;
int a[100],b[100],w[10];
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<m;i++)
{
b[i]=a[i];
for(r=0;r<m;r++)
printf("%d ",b[r]);
printf("\n");
pagef++;
}
for(i=m;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)
{
for(l=0;l<m;l++)
{
for(p=i-1;p>=0;p--)
{
if(b[l]==a[p])
{
w[l]=p;
break;
}
}
if(p==n)
{
b[l]=a[i];
break;
}
}
if(l==m)
{
h=lrupage(w,m);
b[h]=a[i];
}
for(r=0;r<m;r++)
printf("%d ",b[r]);
printf("\n");
pagef++;
}
}
printf("number of page faults: %d",pagef);
}
int lrupage(int w[],int m)
{
int max,k,h=0;
max=w[0];
for(k=1;k<m;k++)
if(w[k]<max)
{
max=w[k];
h=k;
}
return h;
}
INPUT AND OUTPUT

enter the number of pages 20


enter the number of frames in main memory 3
enter the element 0
7
enter the element 1
0
enter the element 2
1
enter the element 3
2
enter the element 4
0
enter the element 5
3
enter the element 6
0
enter the element 7
4
enter the element 8
2
enter the element 9
3
enter the element 10
0
enter the element 11
3
enter the element 12
2
enter the element 13
1
enter the element 14
2
enter the element 15
0
enter the element 16
1
enter the element 17
7
enter the element 18
0
enter the element 19
1

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

Week 17 Simulate the following file allocation strategies

a)Sequential

a)Sequential

OBJECTIVE
Program to perform SEQUENTIAL file allocation technique

PROGRAM LOGIC

Step 1: Start the program.

Step 2: Get the number of memory partition and their sizes.

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

allocates that memory block for the requesting process.

Step 5: Best-fit algorithm searches the memory blocks for the smallest hole which can be allocated
to requesting process

and allocates if.

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

memory resources effectively and efficiently.

Step 8: Stop the program.

PROGRAM

#include<stdio.h>

void main()

int a[100],s[10],l[10],n,m,c,i,j,k;

printf("Enter the total memory you want");

scanf("%d",&m);

printf("Enter the Total number of files");

scanf("%d",&n);

for(i=0;i<=m;i++)

a[i]=-1;

for(i=0;i<n;i++)
{

printf("Enter the starting block of file %d\n ",(i+1));

scanf("%d",&s[i]);

printf("Enter the length of the file %d\n",(i+1));

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)

printf("This block was already filled by file %d\n",(a[k]+1));

if(c==0)

for(k=s[i],j=0;j<l[i];j++,k++)

a[k]=i;

printf("The file %d is filled from %d to %d\n",(i+1),s[i],(s[i]+l[i]-1));

}
}

INPUT AND OUTPUT

Enter the total memory you want 35

Enter the Total number of files 5

Enter the starting block of file 1

Enter the length of the file 1

Enter the starting block of file 2

14

Enter the length of the file 2

Enter the starting block of file 3

19

Enter the length of the file 3

Enter the starting block of file 4

28

Enter the length of the file 4

Enter the starting block of file 5

Enter the length of the file 5

The file 1 is filled from 1 to 2

The file 2 is filled from 14 to 17

The file 3 is filled from 19 to 21


The file 4 is filled from 28 to 33

The file 5 is filled from 6 to 10

Week 18 Simulate all File Organization Techniques


a) Single level directory b) Two level c) Hierarchical d) DAG

a) Single level directory

OBJECTIVE

Simulate Single level directory File Organization Technique

PROGRAM LOGIC

Step 1: Start the program.


Step 2: Get the
name of the
directory. Step 3:
get the number
of files.
Step 4: Get the name of the each file.
Step 5: Now each file is in the
form of filled circle Step 6:
Every file is connected with the
given directory
Step 7: Display the connected gragh along with
name using graphicsStep 8: Stop the program.

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();
}
}

INPUT AND OUTPUT

You might also like