09 - Memory Management
09 - Memory Management
#include <stdio.h>
#define MAX 10
void main()
{
int bsize[MAX], psize[MAX], bno, pno, flag[MAX], allocation[MAX];
for (int i = 0; i < MAX; i++)
{
flag[i] = 0;
allocation[i] = -1;
}
printf("Enter no. of blocks: ");
scanf("%d", &bno);
printf("Enter size of each block:\t");
for (int i = 0; i < bno; i++)
scanf("%d", &bsize[i]);
printf("Enter no. of process: ");
scanf("%d", &pno);
printf("Enter size of each process:\t");
for (int i = 0; i < pno; i++)
scanf("%d", &psize[i]);
if (high != -1)
{
allocation[i] = high;
flag[high] = 1;
}
else
allocation[i] = -1;
}
printf("\nProcess No.\tSize\t\tBlock No\tSize\t\tRemaining\n");
for (int i = 0; i < pno; i++)
{
if (allocation[i] == -1)
printf("%d\t\t%d\t\tNot Allocated\n", i + 1, psize[i]);
else
printf("%d\t\t%d\t\t%d\t\t%d\t\t%d\n", i + 1, psize[i], allocation[i] + 1,
bsize[allocation[i]], bsize[allocation[i]] - psize[i]);
}
return 0;
}