From 605d1bb37b76ab712cc3cfb5e6177a3f548634fb Mon Sep 17 00:00:00 2001 From: Akshaj1017 <92584055+Akshaj1017@users.noreply.github.com> Date: Fri, 14 Oct 2022 00:24:29 +0530 Subject: [PATCH] Create First_Fit_Algorithm --- Algorithms/OS Algorithms/First_Fit_Algorithm | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Algorithms/OS Algorithms/First_Fit_Algorithm diff --git a/Algorithms/OS Algorithms/First_Fit_Algorithm b/Algorithms/OS Algorithms/First_Fit_Algorithm new file mode 100644 index 00000000..2fa84c6b --- /dev/null +++ b/Algorithms/OS Algorithms/First_Fit_Algorithm @@ -0,0 +1,37 @@ +#This code is for the implementation for of first fit algoithm in OS +#include +void implimentFirstFit(int blockSize[], int blocks, int processSize[], int processes) +{ + +int allocate[processes]; for(int i = 0; i < processes; i++) +{ +allocate[i] = -1; +} + +for (int i = 0; i < processes; i++) +{ +for (int j = 0; j < blocks; j++) { +if (blockSize[j] >= processSize[i]) +{ +allocate[i] = j; +blockSize[j] -= processSize[i]; break; +} +} +} + +printf("\nProcess No.\tProcess Size\tBlock no.\n"); for (int i = 0; i < processes; i++) +{ +printf("%d \t\t\t %d \t\t\t", i+1, processSize[i]); if (allocate[i] != -1) +printf("%d\n",allocate[i] + 1); else +printf("Not Allocated\n"); +} +} + + +void main() +{ +int blockSize[] = {300, 50, 100}; +int processSize[] = {100, 60, 90}; +int m = sizeof(blockSize)/sizeof(blockSize[0]); +int n = sizeof(processSize)/sizeof(processSize[0]); implimentFirstFit(blockSize, m, processSize, n); +}