0% found this document useful (0 votes)
28 views4 pages

OS Lab Manual (1) - 18-21

The document describes simulations of memory allocation using Memory Virtual Table (MVT) and Memory File Table (MFT). It includes code samples to simulate both MVT and MFT, and sample outputs. The MVT simulation allocates memory to processes sequentially until memory is full, tracking total memory used and external fragmentation. The MFT simulation allocates memory in block sizes, tracking number of blocks, internal and external fragmentation.
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)
28 views4 pages

OS Lab Manual (1) - 18-21

The document describes simulations of memory allocation using Memory Virtual Table (MVT) and Memory File Table (MFT). It includes code samples to simulate both MVT and MFT, and sample outputs. The MVT simulation allocates memory to processes sequentially until memory is full, tracking total memory used and external fragmentation. The MFT simulation allocates memory in block sizes, tracking number of blocks, internal and external fragmentation.
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/ 4

3 Block is already allocated

4-------->1
5 Block is already allocated
6-------->1
Do you want to enter more file(Yes - 1/No - 0)1
Enter index starting block and length: 4 2
4 starting block is already allocated
Do you want to enter more file(Yes - 1/No – 0)

Week 4: Simulate MVT and MFT

MVT:
#include<stdio.h>
//#include<conio.h>
void main()
{
intms,mp[10],i,temp,n=0; char ch = 'y'; //clrscr();
printf("\nEnter the total memory available (in Bytes)-- ");
scanf("%d",&ms);
temp=ms;
for(i=0;ch=='y';i++,n++)
{
printf("\nEnter memory required for process %d (in Bytes) -- ",i+1);
scanf("%d",&mp[i]);
if(mp[i]<=temp)
{
printf("\nMemory is allocated for Process %d ",i+1);
temp = temp - mp[i];
}
else
{
printf("\nMemory is Full");
break;
}
printf("\nDo you want to continue(y/n) -- ");
scanf(" %c", &ch);
}
printf("\n\nTotal Memory Available -- %d", ms);
printf("\n\n\tPROCESS\t\t MEMORY ALLOCATED ");
for(i=0;i<n;i++)
printf("\n \t%d\t\t%d",i+1,mp[i]);
printf("\n\nTotal Memory Allocated is %d",ms-temp);
printf("\nTotal External Fragmentation is %d",temp);
//getch();
}
Output:

MFT:
#include<stdio.h>
void main()
{
intms,bs,nob,ef,n,mp[10],tif=0;
inti,p=0;

printf("enter the total memory available(in Bytes)--");


scanf("%d",&ms);
printf("enter the block size(in bytes)--");
scanf("%d",&bs);
nob=ms/bs;
ef=ms-nob*bs;
printf("\n enter the number of processes");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter money required for processer %d (in bytes)--",i+1);
scanf("%d",&mp[i]);
}
printf("\n no.of blocks available in memory--%d",nob);
printf("\n \n PROCESS \t MEMORY REQUIRED \t ALLOCATED \t INTERNAL
FRAGMENTATION");
for(i=0;i<n &&p<nob;i++)
{
printf("\n %d \t \t %d",i+1,mp[i]);
if(mp[i]>bs)
printf("\t \t NO \t \t");
else
{
printf("\t \t YES \t %d",bs-mp[i]);
tif=tif+bs-mp[i];
p++;
}
}
if(i<n)
printf("\n Memory is full,remaining processes cannot be accomodated");
printf("\n \n Total Internal Fragmentation is %d",tif);
printf("\n T0tal External Fragmentation is %d",ef);
}
Output:

You might also like