EX - NO.9 Implementation of Memory Management - Deallocation
EX - NO.9 Implementation of Memory Management - Deallocation
ALGORITHM Step - 1: Step - 2: Step - 3: Step - 4: Step 5: Step - 6: Step - 7: Step - 8: Step 9: Step 10: Step 11: outline void main() { int nf,i,npreq,nfinish,fin[5]; fstart=(struct freenode*)malloc(sizeof(struct freenode)); struct allocnode *a,*aptr; astart=(struct allocnode*)malloc(sizeof(struct allocnode)); pstart=(struct process*)malloc(sizeof(struct process)); struct freenode *ftemp; Get the no. of. available free holes & its size, start address, ending address and form a free list Get the no. of. Allocated process requests, its size, start and end address and process ID and form a allocated list Get the no. of. finished process quests, and its process ID Start from then first finished process request Compare its pid with pid of each node in the allocated list if any one alloc node matches, create a node for the free space and assign F->start =alloc->start; F->end=alloc->end Remove that alloc node in the allocated list call merge() to merge the free holes if possible Get the next finished process request and go to step 4 print the allocated list and free list End
printf("Enter the no.of.frames"); scanf("%d",&nf); printf("\nEnter size, start address ,end address "); ftemp=(struct freenode*)malloc(sizeof(struct freenode)); scanf("%d %d %d",&ftemp->size,&ftemp->start,&ftemp->end); ftemp->link=NULL; insertfreenode(ftemp,i); free(ftemp); displayfreenode(); } printf("Enter No.of.Process Request :"); scanf("%d",&npreq); struct process *ptemp; for(i=0;i<npreq;i++) { printf("Enter pid,size "); ptemp=(struct process *)malloc(sizeof(struct process)); scanf("%d %d",&ptemp->pid,&ptemp->size); ptemp->link=NULL; insertprocessnode(ptemp,i); free(ptemp); displayprocessnode(); } firstfit(); displayprocessnode(); displayfreenode(); displayallocnode(); a=astart; printf("Enter the No.of.finished process"); scanf("%d",&nfinish); for(i=0;i<nfinish;i++) { printf("\nEnter the finished process id"); scanf("%d",&fin[i]); while(a!=NULL) { if(a->pid==fin[i]) { if(a->link!=NULL) aptr->link=a->link; else aptr->link=NULL; //displayallocnode(); printf("Before dealloctn"); displayfreenode();
insertfree(a); printf("After dealloctn"); displayfreenode(); printf("After Merging"); merge(); displayfreenode(); break; } aptr=a; a=a->link; // } } displayfreenode(); printf("\n After allocation\n"); displayallocnode();
// } SAMPLE OUTPUT
Enter the no.of.free frames3 Enter size, start address ,end address 100 0 99 first 100 0 99 frame size start_addr End_addr ******************************************* 100 0 99 Enter size, start address ,end address 400 200 349 frame size start_addr End_addr ******************************************* 100 400 0 200 99 349
Enter size, start address ,end address 300 700 899 frame size start_addr End_addr ******************************************* 100 400 300 0 200 700 99 349 899
Allocated list pid 1 start end ************************** 350 399 Enter pid,start,end 2 900 999 Allocated list pid 1 2 start end ************************** 350 399 900 999
frame size start_addr End_addr ******************************************* 100 400 300 Allocated list pid 1 2 start end ************************** 350 399 900 999 0 200 700 99 349 899
Before Deallocation
Enter the No.of.finished process2 Enter the finished process id 1 Before dealloctn frame size start_addr End_addr ******************************************* 100 400 300 0 200 700 99 349 899
After dealloctn frame size start_addr End_addr ******************************************* 100 400 50 300 After Merging frame size start_addr End_addr ******************************************* 100 450 300 Allocated list pid start end ************************** 2 900 999 Enter the finished process id2 frame size start_addr End_addr ******************************************* 100 450 300 0 200 700 99 399 899 0 200 700 99 399 899 0 200 350 700 99 349 399 899
frame size start_addr End_addr ******************************************* 100 450 400 Allocated list pid start end ************************** EMpty list [canitha@192 ~]$ 0 200 700 99 399 999
After Deallocation
EX.NO.10
AIM To write a program to simulate contiguous file allocation in disk ALGORITHM Step 1: Get the no. of. blocks in a disk Step 2: Get the no. of. requests and the filename and no .of. blocks ie length for each filename Step 3: Initialize the status of all blocks as 0 to indicate it is free Step 4:For each file request, A. Initialize count to 0 B. Start from the first block to the last block C. If blk is free, increment count D. If count==length, space is available for the file request E. Make an entry in directory structure by writing filename, start blk no. and length Step 5: print the directory entry structure Step 6:print the free blocks which status value is 0 SAMPLE OUTPUT [canitha@192 ~]$ ./a.out Enter the no.of.blocks in a disk :5 Enter the No.of.Request3 Enter the filename :a1 2 Enter the length(No.of blocks) :found Enter the filename :a2 4 Enter the length(No.of blocks) : No space for the file :a2 Enter the filename :a3 1 Enter the length(No.of blocks) :found directory structure