Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include <iostream>
- #include<math.h>
- using namespace std;
- #define MAX 50
- int main(){
- int page[MAX],i,n,f,ps,off,pno,ProcessSize, internalFrag;
- int choice=0;
- //printf("\nEnter the no of peges in memory: ");
- //scanf("%d",&n);
- printf("\nEnter page size: ");
- scanf("%d",&ps);
- printf("\nEnter process size: ");
- scanf("%d",&ProcessSize);
- n = ceil(ProcessSize / (ps*1.0)) ;
- //cout << "n: " << n << endl;
- internalFrag = ps - (ProcessSize % ps);
- cout << "Internal fragmentation: \n" << internalFrag << endl;
- printf("\nEnter no of frames: ");
- scanf("%d",&f);
- for(i=0;i<n;i++)
- page[i]=-1;
- printf("\nEnter the page table\n");
- printf("(Enter frame no as -1 if that page is not present in any frame)\n\n");
- printf("\npageno\tframeno\n-------\t-------");
- for(i=0;i<n;i++){
- printf("\n\n%d\t\t",i);
- scanf("%d",&page[i]);
- }
- do{
- printf("\n\nEnter the logical address(i.e,page no & offset):");
- scanf("%d%d",&pno,&off);
- if(page[pno]==-1)
- printf("\n\nThe required page is not available in any of frames");
- else
- printf("\n\nPhysical address(i.e,frame no & offset):%d,%d",page[pno],off);
- printf("\nDo you want to continue(1/0)?:");
- scanf("%d",&choice);
- }while(choice==1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement