Академический Документы
Профессиональный Документы
Культура Документы
SLOT:L47+L48
NAME SHAMBEL GONFA
REGGISTER NUMBER 18BCE2429
SUBMITTED TO:
PROF. JAGALIGAM
CONTIGOUS ALLOCATION
AIM: Write a C Program to implement contigous File Allocation method.
ALGORITHM:
Step 1: Start the program.
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
Step 6: Worst fit algorithm searches the memory blocks for the largest hole and
Step 7: Analyses all the three memory management techniques and display the best
#include<stdio.h>
#include<conio.h>
main()
int n,i,j,b[20],sb[20],x,t[20],c[20][20];
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
scanf("%d",&sb[i]);
t[i]=sb[i];
for(j=0;j<b[i];j++)
c[i][j]=sb[i]++;
printf("FILE\tSTART\tLENGTH\n");
for(i=0;i<n;i++)
printf("%d\t %d \t%d\n",i+1,t[i],b[i]);
while(1)
printf("FILE NAME:%d\n",x);
printf("LENGTH:%d\n",b[x-1]);
printf("BLOCKS OCCUPIED:");
for(i=0;i<b[x-1];i++)
printf("%4d\n",c[x-1][i]);
}
LINKED FILE ALLOCATION
AIM: Write a C Program to implement Linked File Allocation method.
ALGORITHM:
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 5: When the page fault occurs replace page present at the bottom of the stack
PROGRAM
#include<stdio.h>
#include<conio.h>
struct file
char fname[10];
int start,size,block[10];
}f[10];
main()
int i,j,n;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",&f[i].fname);
scanf("%d",&f[i].start);
f[i].block[0]=f[i].start;
scanf("%d",&f[i].size);
for(j=1;j<=f[i].size;j++)
scanf("%d",&f[i].block[j]);
printf("File\tstart\tsize\tblock\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\t",f[i].fname,f[i].start,f[i].size);
for(j=1;j<=f[i].size-1;j++)
printf("%d--->",f[i].block[j]);
printf("%d",f[i].block[j]);
printf("\n");
getch();
}
OUT PUT
INDEXED FILE ALLOCATION
AIM: Write a C Program to implement Indexed File Allocation method.
Algorithm:
Step 1: Start.
Step 7: Check there is any cosumer.If yes check whether the buffer is empty
Step 10: Repeat checking for the producer and consumer till required
PROGRAM
#include<stdio.h>
#include<conio.h>
main()
int n,m[20],i,j,sb[20],s[20],b[20][20],x;
scanf("%d",&n);
for(i=0;i<n;i++)
{ printf("Enter starting block and size of file%d:",i+1);
scanf("%d%d",&sb[i],&s[i]);
scanf("%d",&m[i]);
for(j=0;j<m[i];j++)
scanf("%d",&b[i][j]);
printf("\nFile\t index\tlength\n");
for(i=0;i<n;i++)
printf("%d\t%d\t%d\n",i+1,sb[i],m[i]);
while(1)
scanf("%d",&x);
i=x-1;
printf("Index is:%d",sb[i]);
for(j=0;j<m[i];j++)
printf("%3d",b[i][j]);
}
OUTPUT
SCAN
CODE#include<conio.h>
#include<stdio.h>
int main()
int i,j,sum=0,n;
int d[20];
int temp,max;
scanf("%d",&n);
scanf("%d",&disk);
for(i=0;i<n;i++)
scanf("%d",&d[i]);
d[n]=disk;
n=n+1;
for(j=i;j<n;j++)
{
if(d[i]>d[j])
temp=d[i];
d[i]=d[j];
d[j]=temp;
max=d[n];
for(i=dloc;i>=0;i--)
printf("%d -->",d[i]);
printf("0 -->");
for(i=dloc+1;i<n;i++)
printf("%d-->",d[i]);
sum=disk+max;
return 0;
OUTPUT
C SCAN
CODE
#include<stdio.h>
int main()
scanf("%d'",&n);
t[0]=0;t[1]=h;
scanf("%d",&tot);
t[2]=tot-1;
for(i=3;i<=n+2;i++)
scanf("%d",&t[i]);
for(i=0;i<=n+2;i++)
for(j=0;j<=(n+2)-i-1;j++)
if(t[j]>t[j+1])
{ temp=t[j];
t[j]=t[j+1]; t[j+1]=temp;
}
for(i=0;i<=n+2;i++)
if(t[i]==h)
j=i;
p=0;
while(t[j]!=tot-1)
atr[p]=t[j];
j++;
p++;
atr[p]=t[j];
p++;
i=0;
{ atr[p]=t[i]; i++;
p++;
for(j=0;j<n+2;j++)
if(atr[j]>atr[j+1]) d[j]=atr[j]-atr[j+1];
else d[j]=atr[j+1]-atr[j];
sum+=d[j];
printf("avg is %f",(float)sum/n);
getch();
}
FCFS
CODE
#include<stdio.h>
int main()
{
int queue[20],n,head,i,j,k,seek=0,max,diff;
float avg;
printf("Enter the max range of disk\n");
scanf("%d",&max);
printf("Enter the size of queue request\n");
scanf("%d",&n);
printf("Enter the queue of disk positions to be read\n");
for(i=1;i<=n;i++)
scanf("%d",&queue[i]);
printf("Enter the initial head position\n");
scanf("%d",&head);
queue[0]=head;
for(j=0;j<=n-1;j++)
{
diff=abs(queue[j+1]-queue[j]);
seek+=diff;
printf("Disk head moves from %d to %d with
seek %d\n",queue[j],queue[j+1],diff);
}
printf("Total seek time is %d\n",seek);
avg=seek/(float)n;
printf("Average seek time is %f\n",avg);
return 0;
}
OUT PUT
SSFS
CODE
#include<stdio.h>
struct head
{
int num;
int flag;
};
int main()
{
struct head h[33];
int array_1[33], array_2[33];
int count = 0, j, x, limit, minimum, location, disk_head, sum = 0;
printf("\nEnter total number of locations:\t");
scanf("%d", &limit);
printf("\nEnter position of disk head:\t");
scanf("%d", &disk_head);
printf("\nEnter elements of disk head queue\n");
while(count < limit)
{
scanf("%d", &h[count].num);
h[count].flag = 0;
count++;
}
for(count = 0; count < limit; count++)
{
x = 0;
minimum = 0;
location = 0;
for(j = 0; j < limit; j++)
{
if(h[j].flag == 0)
{
if(x == 0)
{
array_1[j] = disk_head - h[j].num;
if(array_1[j] < 0)
{
array_1[j] = h[j].num - disk_head;
}
minimum = array_1[j];
location = j;
x++;
}
else
{
array_1[j] = disk_head - h[j].num;
if(array_1[j] < 0)
{
array_1[j] = h[j].num - disk_head;
}
}
if(minimum > array_1[j])
{
minimum = array_1[j];
location = j;
}
}
}
h[location].flag = 1;
array_2[count] = h[location].num - disk_head;
if(array_2[count] < 0)
{
array_2[count] = disk_head - h[location].num;
}
disk_head = h[location].num;
}
count = 0;
while(count < limit)
{
sum = sum + array_2[count];
count++;
}
printf("\nTotal movements of the cylinders:\t%d", sum);
return 0;
}
OUT PUT
LOOK
CODE
#include <stdio.h>
#include <stdlib.h>
#define LOW 0
#define HIGH 199
int main(){
int queue[20], head, q_size, i,j, seek=0, diff, max, temp, queue1[20], queue2[20], temp1=0, temp2=0;
float avg;
} else {
}
queue[0] = head;
return 0;
}
OUT PUT