Write a program to implement the Dynamic allocation of memories in Multiprogram Variable Task.

Algorithm for Multiprogram Variable Task:
Step1: start the process.
Step2: Declare variables.
Step3: Enter total memory size.
Step4: Allocate memory for the OS.
Step5: allocate total memory to the pages.
Step6: Display the wastage of memory.
Step7: Stop the process.

/* Program to simulate the MVT */
Program Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int m,i,p[15];
char ch;
clrscr();
printf("Enter memory to be allocated: ");
scanf("%d",&m);
printf("Enter process size : ");
scanf("%d", &p[0]);
i=0;
do
{
m=m-p[i];
printf("\nRemaining memory is %d\n",m);
abc:printf("Do you want to continue: ");
fflush(stdin);
scanf("%c",&ch);
i++;
if(ch=='y')
{
printf("Enter the process size: ");
scanf("%d",&p[i]);
}
else
{
printf("\nExternal fragmentation is %d",m);
break;
}
if(m<p[i])
{
printf("\nRequired memory is not available\n");
goto abc;
}
}while((ch=='y')&&(m>=p[i]));
getch();
}



Program Output:
Enter memory to be allocated: 1000
Enter process size : 500
Remaining memory is 500
Do you want to continue: y
Enter the process size: 300
Remaining memory is 200
Do you want to continue: y
Enter the process size: 100
Remaining memory is 100
Do you want to continue: n
External fragmentation is 100
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: