Sunday 9 August 2015

Implementation of First Fit Memory Management technique

Program:

#include<stdio.h>
#include<conio.h>
#define SIZE 20
void main(){
int np,nm,i,j,p[SIZE],m[SIZE],allocated[SIZE]={0},remaining[SIZE],flag;
clrscr();
 printf("Enter no. of processes:");
 scanf("%d",&np);
 printf("Enter no. of Memory Blocks");
 scanf("%d",&nm);

 printf("\n");
  printf("Enter size of processes\n");

 for(i=0;i<np;i++){
  printf(" Process P%d: ",i+1);
  scanf("%d",&p[i]);
 }
 printf("\n");

  printf("Enter size of Memory blocks:\n");
 for(i=0;i<nm;i++){
  printf("Block %d: ",i+1);
  scanf("%d",&m[i]);
 }
 printf("\nProcess\tProcess_size \tBlock no.\tBlock size\tFragement");
 for(i=0;i<np;i++){
 flag=0;
for(j=0;j<nm;j++){
if(m[j]-p[i]>=0 && allocated[j]!=1){
allocated[j]=1;
remaining[j]=m[j]-p[i];
flag=1;
}
if(flag==1)break;

}

      printf("\n%d\t\t%d\t\t",i+1,p[i]);
      if(flag==1)
      printf("%d\t\t%d\t\t%d",j+1,m[j],remaining[j]);
    else
    printf("NA\t\tNA\t\tNA");

 }

 getch();
}




Sample Output:
C program for Implementation of First Fit Memory Management technique

No comments:

Post a Comment