Sie sind auf Seite 1von 6

10BC064

Implementation of Memory Management Scheme: Program: #include<stdio.h> #include<conio.h> struct memory { int blksize; }block[10]; void ff(int nb,int np); void wf(int nb,int np); void bf(int nb,int np); void main() { int np,nb; clrscr(); printf("\nEnter the no of blocks="); scanf("%d",&nb); printf("\nEnter the no of processes="); scanf("%d",&np); printf("\nFIRST FIT"); ff(nb,np); printf("\nBEST FIT"); bf(nb,np); printf("\nWORST FIT"); wf(nb,np); getch(); } void ff(int nb,int np) { int i,j,prosize[10],proflag[10]; for(i=1;i<=nb;i++) { printf("\nenter block %d size=",i); scanf("%d",&block[i].blksize); } for(i=1;i<=np;i++) { printf("\nEnter process %d size",i); scanf("%d",&prosize[i]); proflag[i]=0; } for(i=1;i<=np;i++) {

10BC064

for(j=1;j<=nb;j++) { if((prosize[i]<=block[j].blksize)&&(proflag[i]!=1)) { proflag[i]=1; printf("\nprocess %d has been put into %d",i,block[j].blksize); block[j].blksize=block[j].blksize-prosize[i]; } } } for(i=1;i<=np;i++) { if(proflag[i]==0) { printf("\nprocess %d has to wait",i); } } } void bf(int nb,int np) { int i,j,prosize[10],proflag[10],min,maxm,blkno,flag[10]; for(i=1;i<=nb;i++) { printf("\nenter block %d size=",i); scanf("%d",&block[i].blksize); } for(i=1;i<=np;i++) { printf("\nEnter process %d size",i); scanf("%d",&prosize[i]); proflag[i]=0; flag[i]=0; } printf("\nEnter maximum block size"); scanf("%d",&maxm); for(i=1;i<=np;i++) { min=maxm; for(j=1;j<=nb;j++) { if((prosize[i]<=block[j].blksize)&&(proflag[i]!=1)) { flag[i]=1;

10BC064

if((block[j].blksize-prosize[i])<min) { min=block[j].blksize-prosize[i]; blkno=j; } } } if(flag[i]==1) { printf("\n process %d is put into %d",i,block[blkno].blksize); block[blkno].blksize=block[blkno].blksize-prosize[i]; } else { printf("\n process %d has to wait",i); } } } void wf(int nb,int np) { int i,j,prosize[10],proflag[10],max=0,blkno,flag[10]; for(i=1;i<=nb;i++) { printf("\nenter block %d size=",i); scanf("%d",&block[i].blksize); } for(i=1;i<=np;i++) { printf("\nEnter process %d size",i); scanf("%d",&prosize[i]); proflag[i]=0; flag[i]=0; } for(i=1;i<=np;i++) { max=0; for(j=1;j<=nb;j++) { if((prosize[i]<=block[j].blksize)&&(proflag[i]!=1)) { flag[i]=1; if((block[j].blksize-prosize[i])>max) {

10BC064

max=block[j].blksize-prosize[i]; blkno=j; } } } if(flag[i]==1) { printf("\n process %d is put into %d",i,block[blkno].blksize); block[blkno].blksize=block[blkno].blksize-prosize[i]; } else { printf("\n process %d has to wait",i); } } }

Output: Enter the no of blocks=5 Enter the no of processes=4 FIRST FIT enter block 1 size=100 enter block 2 size=500 enter block 3 size=200 enter block 4 size=300 enter block 5 size=600 Enter process 1 size212 Enter process 2 size417 Enter process 3 size112

10BC064

Enter process 4 size426 process 1 has been put into 500 process 2 has been put into 600 process 3 has been put into 288 process 4 has to wait BEST FIT enter block 1 size=100 enter block 2 size=500 enter block 3 size=200 enter block 4 size=300 enter block 5 size=600 Enter process 1 size212 Enter process 2 size417 Enter process 3 size112 Enter process 4 size426 Enter maximum block size600 process 1 is put into 300 process 2 is put into 500 process 3 is put into 200 process 4 is put into 600 WORST FIT enter block 1 size=100 enter block 2 size=500 enter block 3 size=200 enter block 4 size=300 enter block 5 size=600

10BC064

Enter process 1 size212 Enter process 2 size417 Enter process 3 size112 Enter process 4 size426 process 1 is put into 600 process 2 is put into 500 process 3 is put into 388 process 4 has to wait

Result: Thus the program is typed, executed and output is verified to be correct.

Das könnte Ihnen auch gefallen