-
Notifications
You must be signed in to change notification settings - Fork 1
/
7b.c
54 lines (43 loc) · 1.12 KB
/
7b.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//MFT Memory management technique
#include <stdio.h>
int main(int argc, char const *argv[])
{
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 no. of processes: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("Enter memory required for process %d (in Bytes): ", i + 1);
scanf("%d", &mp[i]);
}
printf("\nNo. of Blocks available in memory: %d", nob);
printf("\n\nProcess\t\tMemory Required\tAllocated\tInternal Fragmentation");
for (i = 0; i < n; 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\t%d", bs - mp[i]);
tif = tif + bs - mp[i];
p++;
}
}
if (i < n)
{
printf("\n\nMemory is Full, Remaining processes cannot be accomodated.");
}
printf("\nTotal Internal Fragmentation is: %d", tif);
printf("\nTotal External Fragmentation is: %d\n", ef);
return 0;
}