Experiment 4: Write a C program to simulate the MFT(MULTIPROGRAM FIXED TASK) and
MVT(MULTIPROGRAM VARIABLE TASK) memory management
techniques.
(A)
Aim: To implement and simulate the MFT(MULTIPROGRAM FIXED TASK) algorithm.
#include<stdio.h>
int main()
{
int ms,i,ps[20],n,size,p[20],s,intr=0; /*ms-main memory size,i for loop
repetation, ps is size of each process,n is number of processes, size- size of each
partition, p-process identity, s-size of operating system, intr-for calculation
internal fragmentation*/
printf("Enter size of memory:");
scanf("%d",&ms);
printf("Enter memory for OS:");
scanf("%d",&s);
ms-=s;
printf("Enter [Link] partitions to be divided:");
scanf("%d",&n);
size=ms/n;
for(i=0;i<n;i++)
{
printf("\n Enter process and process size:");
scanf("%d%d",&p[i],&ps[i]); /*process id and process size*/
if(ps[i]<=size)
{
intr=intr+size-ps[i]; /*intr is 0 means there is no internal
fragmentation*/
printf("process%d is allocated\n",p[i]);
}
else
printf("\n process%d is blocked",p[i]);
}
printf("\n internal fragmentation is %d",intr);
return 0;
}
Output:
Enter size of memory:100
Enter memory for OS:40
Enter [Link] partitions to be divided:4
Enter process and process size:1 15
process1 is allocated
Enter process and process size:2 30
process2 is blocked
Enter process and process size:3 5
process3 is allocated
Enter process and process size:4 40
process4 is blocked
internal fragmentation is 10
(B)
Aim: To implement and simulate the MVT(MULTIPROGRAM VARIABLE TASK) algorithm.
#include<stdio.h>
int main()
{
int i,m,n,tot,s[20];
printf("Enter total memory size:");
scanf("%d",&tot);
printf("Enter no. of processes:");
scanf("%d",&n);
printf("Enter memory for OS:");
scanf("%d",&m);
for(i=0;i<n;i++)
{
printf("Enter size of process %d:",i+1);
scanf("%d",&s[i]);
}
tot=tot-m;
for(i=0;i<n;i++)
{
if(tot>=s[i])
{
printf("\nProcess %d is allocated ",i+1);
tot=tot-s[i];
}
else
printf("\nprocess p%d is not allocated\n",i+1);
}
printf("External Fragmentation is=%d",tot);
return 0;
}
Output:
Enter total memory size:100
Enter no. of processes:4
Enter memory for OS:40
Enter size of process 1:15
Enter size of process 2:30
Enter size of process 3:5
Enter size of process 4:35
Process 1 is allocated
Process 2 is allocated
Process 3 is allocated
process p4 is not allocated
External Fragmentation is=10