Memorymanagement Osexp89 2
Memorymanagement Osexp89 2
EXPERIMENT NO - 8(A)
AIM - A) Write a program to demonstrate the concept of MVT and MFT memory
management technique .
PROGRAM-(MVT)
#include<stdio.h>
void main() {
int ms, bs, nob, ef, n, mp[10], tif = 0;
int i, 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("\nEnter the number of processes -- ");
scanf("%d", &n);
OUTPUT :
PROGRAM-(MFT)
#include<stdio.h>
void main() {
int ms, mp[10], i, temp, n = 0;
char ch = 'y';
temp = ms;
} else {
printf("\nMemory is Full");
break;
}
printf("\nDo you want to continue (y/n) -- ");
scanf(" %c", &ch); // The space before %c handles the newline character
from previous input
}
printf("\n\nTotal Memory Available -- %d", ms);
printf("\n\n\tPROCESS\t\tMEMORY ALLOCATED");
PROGRAM (FIRST-FIT)
#include<stdio.h>
#define MAX 25
void main() {
int frag[MAX], b[MAX], f[MAX], bf[MAX], ff[MAX];
int i, j, nb, nf, temp;
printf("\n\tMemory Management Scheme - First Fit");
printf("\nEnter the number of blocks: ");
scanf("%d", &nb);
printf("Enter the number of files: ");
scanf("%d", &nf);
printf("\nEnter the size of the blocks:\n");
OUTPUT :
PROGRAM (BEST-FIT)
#include<stdio.h>
#define MAX 25
void main() {
int frag[MAX], b[MAX], f[MAX], i, j, nb, nf, temp, lowest;
static int bf[MAX], ff[MAX];
frag[i] = lowest;
bf[ff[i]] = 1;
}
printf("\nFile No\tFile Size\tBlock No\tBlock Size\tFragmentation");
for(i = 1; i <= nf; i++) {
if(ff[i] != 0) {
printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d", i, f[i], ff[i], b[ff[i]], frag[i]);
} else {
printf("\n%d\t\t%d\t\tNot Allocated\t\t-\t\t-", i, f[i]);
}
}
printf("\n");
}
OUTPUT :
PROGRAM (WORST-FIT)
#include<stdio.h>
#define MAX 25
void main() {
int frag[MAX], b[MAX], f[MAX], i, j, nb, nf, temp, highest;
static int bf[MAX], ff[MAX];
if(highest != -1) {
frag[i] = highest;
bf[ff[i]] = 1;
}
}
printf("\n");
}
OUTPUT :
OUTPUT :
void display();
void main() {
int p[12] = {2, 3, 2, 1, 5, 2, 4, 5, 3, 2, 5, 2};
int i, j, fs[3], index, k, flag1 = 0, flag2 = 0, pf = 0, frsize = 3;
if(flag1 == 0) {
for(i = 0; i < 3; i++) {
if(fr[i] == -1) {
fr[i] = p[j];
flag2 = 1;
break;
}
}
}
if(flag2 == 0) {
for(i = 0; i < 3; i++) {
fs[i] = 0;
}
fr[index] = p[j];
pf++;
}
display();
}
void display() {
int i;
printf("\n");
for(i = 0; i < 3; i++) {
printf("%d\t", fr[i]);
}
}
OUTPUT :