0% found this document useful (0 votes)
8 views3 pages

dg 6

The document outlines an experiment to calculate external and internal fragmentation in memory allocation. It includes a C program that prompts the user for memory block sizes and process sizes, then implements a First Fit Allocation strategy to determine fragmentation. The program outputs the total internal and external fragmentation values after processing the inputs.

Uploaded by

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

dg 6

The document outlines an experiment to calculate external and internal fragmentation in memory allocation. It includes a C program that prompts the user for memory block sizes and process sizes, then implements a First Fit Allocation strategy to determine fragmentation. The program outputs the total internal and external fragmentation values after processing the inputs.

Uploaded by

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

EXPERIMENT -6

Calculation of external and internal fragmentation i. Free space list of


blocks from system ii. List process file from the system

#include <stdio.h>

int main() {
int m, n, i, total_internal = 0, total_memory = 0, total_allocated = 0;

printf("Enter number of memory blocks: ");


scanf("%d", &m);
int block_size[m];
printf("Enter sizes of memory blocks:\n");
for (i = 0; i < m; i++) {
scanf("%d", &block_size[i]);
total_memory += block_size[i];
}

printf("Enter number of processes: ");


scanf("%d", &n);
int process_size[n];
int allocation[m];
for (i = 0; i < m; i++) allocation[i] = -1;

printf("Enter sizes of processes:\n");


for (i = 0; i < n; i++) {
scanf("%d", &process_size[i]);
}

// First Fit Allocation


for (i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (block_size[j] >= process_size[i]) {
allocation[j] = i;
total_internal += block_size[j] - process_size[i];
total_allocated += block_size[j];
block_size[j] = 0;
break;
}
}
}

int total_external = total_memory - total_allocated;

printf("\nTotal Internal Fragmentation: %d\n", total_internal);


printf("Total External Fragmentation: %d\n", total_external);

return 0;
}
Output-----

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy