Advertisement
JagadeeshUndavalli

Paging

Jul 26th, 2022
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4.  
  5.     int ms,ps,nop,np,x,y,offset,rempages,i,j,pa;
  6.     int s[10], ft[10][20];
  7.     printf("\nEnter the size of memory : ");
  8.     scanf("%d",&ms);
  9.     printf("Enter the size of a page : ");
  10.     scanf("%d",&ps);
  11.     nop = ms/ps;
  12.     printf("No of pages available : %d",nop);
  13.     rempages = nop;
  14.     printf("\nEnter no. of processes : ");
  15.     scanf("%d",&np);
  16.     for(i=0;i<np;i++){
  17.         printf("Enter no. of pages required for p[%d] : ",i);
  18.         scanf("%d",&s[i]);
  19.         if(s[i]>rempages){
  20.             printf("Memory is FULL\n");
  21.             break;
  22.         }
  23.         rempages = rempages - s[i];
  24.         printf("Enter the page table for p[%d] : ",i);
  25.         for(j=0; j<s[i]; j++){
  26.             scanf("%d",&ft[i][j]);
  27.         }
  28.     }
  29.     printf("Enter the Logical address to find physical address\n");
  30.     printf("Enter the process no. page no. and offset : ");
  31.     scanf("%d %d %d",&x,&y,&offset);
  32.     if(x>np||y>=s[i]||offset>=ps){
  33.         printf("\nInvalid process no. or page no. or offset");
  34.     }else{
  35.         pa = ft[x][y]*ps + offset;
  36.         printf("The Physical Address is : %d", pa);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement