0% found this document useful (0 votes)
11 views

Experiment 2-os record

The document outlines two experiments simulating memory management techniques: Multiprogramming with a Fixed number of Tasks (MFT) and Multiprogramming with a Variable number of Tasks (MVT). The MFT program allocates memory to processes based on fixed block sizes, calculating internal and external fragmentation, while the MVT program allocates memory dynamically until the available memory is exhausted. Both programs demonstrate the allocation process and fragmentation outcomes through user input and display results accordingly.

Uploaded by

lavarajugadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Experiment 2-os record

The document outlines two experiments simulating memory management techniques: Multiprogramming with a Fixed number of Tasks (MFT) and Multiprogramming with a Variable number of Tasks (MVT). The MFT program allocates memory to processes based on fixed block sizes, calculating internal and external fragmentation, while the MVT program allocates memory dynamically until the available memory is exhausted. Both programs demonstrate the allocation process and fragmentation outcomes through user input and display results accordingly.

Uploaded by

lavarajugadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment 2:

AIM :Simulate the following:


a) Multiprogramming with a fixed number of tasks (MFT)
b) Multiprogramming with a variable number of tasks (MVT)
PROGRAM :
A) MFT MEMORY MANAGEMENT TECHNIQUE (MFT)

#include<stdio.h>
int main()
{
int ms, bs, nob, ef, n, mp[10], tif = 0;
int i, p = 0;
// Getting the memory size, block size and number of processes
printf("Enter the total memory available (in Bytes) -- ");
scanf("%d", &ms);
printf("Enter the block size (in Bytes) -- ");
scanf("%d", &bs);
nob = ms / bs; // Number of blocks available
ef = ms - nob * bs; // External fragmentation
printf("\nEnter the number of processes -- ");
scanf("%d", &n);
// Getting the memory required by each process
for (i = 0; i < n; i++)
{
printf("Enter memory required for process %d (in Bytes)-- ", i + 1);
scanf("%d", &mp[i]);
}
// Displaying the number of blocks available
printf("\nNo. of Blocks available in memory -- %d", nob);
printf("\n\nPROCESS\tMEMORY REQUIRED\t ALLOCATED\tINTERNAL FRAGMENTATION");
// Process allocation
for (i = 0; i < n && p < nob; i++)
{
printf("\n %d\t\t%d", i + 1, mp[i]);
if (mp[i] > bs)
printf("\t\tNO\t\t---");
else
{
printf("\t\tYES\t%d", bs - mp[i]);
tif = tif + bs - mp[i];
p++;
}
}
// If not all processes are accommodated
if (i < n)
printf("\nMemory is Full, Remaining Processes cannot be accomodated");
// Displaying total internal and external fragmentation
printf("\n\nTotal Internal Fragmentation is %d", tif);
printf("\nTotal External Fragmentation is %d", ef);
}
Out put:
Enter the total memory available (in Bytes) -- 1000
Enter the block size (in Bytes) -- 300
Enter the number of processes -- 5
Enter memory required for process 1 (in Bytes)-- 275
Enter memory required for process 2 (in Bytes)-- 400
Enter memory required for process 3 (in Bytes)-- 290
Enter memory required for process 4 (in Bytes)-- 293
Enter memory required for process 5 (in Bytes)-- 100
No. of Blocks available in memory -- 3
PROCESS MEMORY REQUIRED ALLOCATED INTERNALFRAGMENTATION

1 275 YES 25

2 400 NO ---

3 290 YES 10

4 293 YES 7
Memory is Full, Remaining Processes cannot be accomodated
Total Internal Fragmentation is 42
Total External Fragmentation is 100
*****************************************************************************

B) MVT MEMORY MANAGEMENT TECHNIQUE (MVT)


#include<stdio.h>
int main()
{
int ms,mp[10],i, temp,n=0;
char ch = 'y';
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);
}
Out put:
Enter the total memory available (in Bytes)-- 1000
Enter memory required for process 1 (in Bytes) -- 400
Memory is allocated for Process 1
Do you want to continue(y/n) -- y
Enter memory required for process 2 (in Bytes) -- 275
Memory is allocated for Process 2
Do you want to continue(y/n) -- y
Enter memory required for process 3 (in Bytes) -- 550
Memory is Full
Total Memory Available -- 1000
PROCESS MEMORY ALLOCATED

1 400

2 275
Total Memory Allocated is 675
Total External Fragmentation is 325

You might also like