Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create First_Fit_Algorithm #663

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Algorithms/OS Algorithms/First_Fit_Algorithm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#This code is for the implementation for of first fit algoithm in OS
#include <stdio.h>
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);
}