Experiment 2-os record
Experiment 2-os record
#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
*****************************************************************************
1 400
2 275
Total Memory Allocated is 675
Total External Fragmentation is 325