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

Operating Systems Lab-09

Uploaded by

supop3975
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Operating Systems Lab-09

Uploaded by

supop3975
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C) LINKED:

AIM: To implement linked file allocation technique.

DESCRIPTION:
In the chained method file allocation table contains a field which points to starting
block of memory. From it for each bloc a pointer is kept to next successive block. Hence,
there is no external fragmentation

ALGORTHIM:
Step 1: Start the program.
Step 2: Get the number of
files.
Step 3: Get the memory requirement of each file.
Step 4: Allocate the required locations by selecting a location randomly q=
random(100);
a) Check whether the selected location is free .
b) If the location is free allocate and set flag=1 to the allocated locations.
While allocating next location address to attach it to previous location

for(i=0;i<n;i++)
{
for(j=0;j<s[i];j++)
{
q=random(100); if(b[q].flag==0)
b[q].flag=1;
b[q].fno=j;
r[i][j]=q;
if(j>0)
{
}
}
p=r[i][j-1]; b[p].next=q;}
Step 5: Print the results file no, length ,Blocks
allocated.
Step 6: Stop the program

Page 53
SOURCE CODE :
#include<stdio.h>
main()
{
int f[50],p,i,j,k,a,st,len,n,c;
clrscr();
for(i=0;i<50;i++) f[i]=0;
printf("Enter how many blocks that are already
allocated"); scanf("%d",&p);
printf("\nEnter the blocks no.s that are already allocated");
for(i=0;i<p;i++)
{
scanf("%d",&a);
f[a]=1;
}
X:
printf("Enter the starting index block &
length"); scanf("%d%d",&st,&len); k=len;
for(j=st;j<(k+st);j++)
{
if(f[j]==0)
{ f[j]=1;
printf("\n%d->%d",j,f[j]);
}
else
{
printf("\n %d->file is already
allocated",j);
k++;
}
}
printf("\n If u want to enter one
more file? (yes-1/no-0)");
scanf("%d",&c);
if(c==1)
goto
X;
else
exit();
getch( );}

Page 54
OUTPUT:

Enter how many blocks that are already allocated 3 Enter the blocks no.s
that are already allocated 4 7 Enter the starting index block & length 3 7 9
3->1
4->1 file is already allocated
5->1
6->1
7->1 file is already allocated
8->1
9->1file is already allocated
10->1
11->1
12->1

VIVA QUESTIONS
1) List the various types of files
2) What are the various file allocation strategies?
3) What is linked allocation?
4) What are the advantages of linked allocation?
5) What are the disadvantages of sequential allocation methods?

Page 55

You might also like