Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rahul-joy/code-to-solve-the-memory-management-technique-problem
https://github.com/rahul-joy/code-to-solve-the-memory-management-technique-problem
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/rahul-joy/code-to-solve-the-memory-management-technique-problem
- Owner: rahul-joy
- Created: 2023-12-03T15:26:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-03T15:32:25.000Z (about 1 year ago)
- Last Synced: 2023-12-03T16:27:02.503Z (about 1 year ago)
- Language: C
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# code-to-solve-the-Memory-Management-technique-problem
Code
#include
int main() {
int numBlocks, numProcesses;
printf("Enter the number of Blocks: ");
scanf("%d", &numBlocks);
int blockSizes[numBlocks];
for (int i = 0; i < numBlocks; i++) {
printf("Block %d size: ", i + 1);
scanf("%d", &blockSizes[i]);
}
printf("Enter the number of processes: ");
scanf("%d", &numProcesses);
int processSizes[numProcesses];
for (int i = 0; i < numProcesses; i++) {
printf("Enter memory required for process %d: ", i + 1);
scanf("%d", &processSizes[i]);
}
int allocation[numProcesses];
for (int i = 0; i < numProcesses; i++) {
allocation[i] = -1; // Initialize allocation for each process as -1 (unallocated). }
for (int i = 0; i < numProcesses; i++) {
for (int j = 0; j < numBlocks; j++) {
if (blockSizes[j] >= processSizes[i]) {
allocation[i] = j; // Allocate the process to this block.
blockSizes[j] -= processSizes[i]; // Update block size after allocation. break; // Process allocated, move to the next process.
}
}
}
printf("\nProcess\tMemory Size\tBlock\n");
for (int i = 0; i < numProcesses; i++) {
printf("%d\t%d\t\t", i + 1, processSizes[i]);
if (allocation[i] != -1) {
printf("Block %d\n", allocation[i] + 1);
} else {
printf("Not Allocated\n");
}
}
return 0;
}
}Output
![image](https://github.com/rahul-joy/code-to-solve-the-Memory-Management-technique-problem/assets/81201194/8daeae9e-577b-40fb-afee-2f27a37c3e96)