Job Saarnee

JOB SAARNEE

Top Most Platform for Job Updates O Level Results Answer keys AKTU MCQs

Algorithm and Implementation of contiguous allocation techniques: First- Fit using c

 Algorithm and Implementation of contiguous allocation techniques: First- Fit

In order to implement First fit contiguous allocation techniques there is certain requirement first we need Block size, Number of Block that is m, Number of Process is n, Size of each and every process
Let Blocksize is the array of size m.
Let SizeofProcess is the array of size n.
Let AllocationStatus is an array of size n.

it is the function we are going to use First_fitCAT(int Blocksize[ ],int SizeofProcess[ ],AllocationStatus[ ])
 
1- Initilze the  Blocksize with size and SizeofProcess with size.
2- Initialize all AllocationStatus as free.
Note we going to use -1 to indicate the status empty otherwise index of block

3- First take one process and check for the block in which it can be assigned first. 
                 If SizeofProcess <= BlockSize then 
                      Assign the Block to the process and update the status of process in AllocationStatus, 
                      Reduce the Size of Block by Sizeof Process
                 check for next process.

5- check is allocation status for all process is allocated then Print otherwise simple not allocated

Now lets implement the above algorithm in C.

#include<stdio.h>
#include<conio.h>

void First_fitCAT(int Blocksize[ ],int SizeofProcess[ ],int AllocationStatus[ ],int m,int n)
{
int i,j;
for(i=0;i<n;i++)
{
     for(j=0;j<m;j++)
     {
          if(SizeofProcess[i]<=Blocksize[j])
          {
               AllocationStatus[i]=j;
               Blocksize[j]=Blocksize[j]-SizeofProcess[i];
               break;
          }
     }
}

printf(“Process is allocated to following blocksn”);
for(j=0;j<n;j++)
{
   if(AllocationStatus[j]==-1)
   {
      printf(“Process %d is not Allocated n”,j+1);
   }
   else
   {
     printf(“Process %d is Allocated to %dn”,j+1,AllocationStatus[j]+1);
   }


}
}

void main()
{
     int Blocksize[20],SizeofProcess[20];
     int AllocationStatus[20],m,n;
     int i,j;
     printf(“Enter the number of Blockn”);
     scanf(“%d”,&m);
     printf(“now enter the size of block”);
     for(i=0;i<m;i++)
     {
     scanf(“%d”,&Blocksize[i]);
     }
     printf(“Enter the number of Processn”);
     scanf(“%d”,&n);
     printf(“now enter the size required by Process”);
     for(i=0;i<n;i++)
     {
     scanf(“%d”,&SizeofProcess[i]);
     AllocationStatus[i]=-1;
     }
     First_fitCAT(Blocksize,SizeofProcess,AllocationStatus,m,n);
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart

You cannot copy content of this page