• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Paging Algorithms using C language OS problem

April 4, 2011 by ProjectsGeek 2 Comments

 Paging Algorithms Operating System

 

Write the simulation Paging Algorithms program for demand paging and show the page scheduling and total number of page faults according to MFU page replacement algorithm. Assume the memory of ‘n’ frames.

Paging Algorithms using C language

 # include  
 # include  
 # include  
 # define maxn 50  
 typedef struct  page  
 {  
   int frame ;  
   int count[maxn],curr[maxn] ;  
 }page ;  
 struct page p ;  
 void fifo(int pages,int page[]) ;  
 void lru(int pages ,int page[]) ;  
 void optimal(int pages,int page[]) ;  
 void main()  
 {  
  int ch=0,pages=0,i,j,page[maxn],frames=0,temp3,temp4 ;  
  char temp ;  
  clrscr() ;  
  do  
  {  
    printf("\t\t\t\****main menu****\n") ;  
    printf("\t\t\t1.enter the page information\n");  
    printf("\t\t\t2.dispaly page info\n");  
    printf("\t\t\t3.fifo\n" );  
    printf("\t\t\t4.\lru\n") ;  
    printf("\t\t\t5.\optimal\n") ;  
    printf("\t\t\t6.exit\n");  
    printf("\t\t\tenter ur choice\n");  
   scanf("%d",&ch);  
   switch (ch)  
   {  
    case 1:  
      clrscr();  
      printf("enter the no of pages\n");  
      scanf("%d",&pages) ;  
      printf("enter pages\n");  
      for(i=0;i<pages;i++) <br="">      {  
       printf("page %d\n",i);  
       scanf("%d",&page[i]) ;  
      }  
      printf("enter number of frames .....\n");  
      scanf("%d",&p.frame) ;  
      break ;  
    case 2:  
      printf("no of pages%d\n",pages);  
       printf("page sequence \n");  
       for(i=0;i<pages;i++) <br="">       {  
       printf("page %d\n",page[i]);  
       }  
       printf("no of frames/%d",p.frame);  
      break ;  
    case 3:  
       fifo(pages,page) ;  
       break ;  
    case 4:  
       lru(pages ,page);  
      break ;  
    case 5:  
        optimal(pages ,page);  
      break ;  
    case 6:  
      break ;  
   }  
 }while(ch!=6 );  
 }  
 void fifo(int pages,int page[])  
 {  
  int i,j,k,flag=0,temp=0,fault=0 ;  
  for(i=0;i<p.frame;i++) <br="">

  {  
     p.curr[i]=-1 ;  
     p.count[i]=100 ;  
     printf("\tpage%d",i+1) ;  
  }  
  printf("\tfault\n\n");  
  for(i=0;i<pages;i++) <br="">  {  
     flag=0 ;  
     temp=0 ;  
     for(j=0;j<p.frame;j++) <br="">

     {  
           if(p.curr[j]==page[i])  
           {  
             flag=1 ;  
             break ;  
           }  
           if(temp<p.count[j]) <br="">

           {  
               temp=p.count[j] ;  
               k=j ;  
           }  
     }  
     for(j=0;j<p.frame;j++) <br="">

     {  
         if(flag==0 && k==j)  
         {  
           p.curr[j]=page[i] ;  
           p.count[j]=1 ;  
           fault++ ;  
         }  
         else  
         if(j<fault) <br="">         p.count[j]++;  
         if(p.curr[j]!=-1)  
         printf("\t%d",p.curr[j]) ;  
     }  
     if(flag==0)  
     printf("\t\t\t*") ;  
     printf("\n") ;  
  }  
  printf("no of page fault%d",fault);  
 }  
 void lru(int pages ,int page[])  
 {  
  int i,j,k,flag=0,temp=0,fault=0 ;  
  for(i=0;i<p.frame;i++) <br="">

  {  
     p.curr[i]=-1 ;  
     p.count[i]=100 ;  
     printf("\tpage%d",i+1) ;  
  }  
  printf("\tfault\n\n");  
  for(i=0;i<pages;i++) <br="">  {  
     flag=0 ;  
     temp=0 ;  
     for(j=0;j<p.frame;j++) <br="">

     {  
           if(p.curr[j]==page[i])  
           {  
             flag=1 ;  
             p.count[j]=0 ;  
             break ;  
           }  
           if(temp<p.count[j]) <br="">

           {  
               temp=p.count[j] ;  
               k=j ;  
           }  
     }  
     for(j=0;j<p.frame;j++) <br="">

     {  
         if(flag==0 && k==j)  
         {  
           p.curr[j]=page[i] ;  
           p.count[j]=1 ;  
           fault++ ;  
         }  
         else  
         if(j<fault) <br="">         p.count[j]++;  
         if(p.curr[j]!=-1)  
         printf("\t%d",p.curr[j]) ;  
     }  
     if(flag==0)  
     printf("\t\t\t*") ;  
     printf("\n") ;  
  }  
  printf("no of page fault%d",fault);  
 }  
 void optimal(int pages,int page[])  
 {  
  int i,j,k,flag=0,temp=0,fault=0,s ;  
  for(i=0;i<p.frame;i++) <br="">

  {  
     p.curr[i]=-1 ;  
     p.count[i]=100 ;  
     printf("\tpage%d",i+1) ;  
  }  
  printf("\tfault\n\n");  
  for(i=0;i<pages;i++) <br="">  {  
     flag=0 ;  
     temp=0 ;  
     for(j=0;j<p.frame;j++) <br="">

     {  
           if(p.curr[j]==page[i])  
           {  
             flag=1 ;  
             p.count[j]=0 ;  
             break ;  
           }  
           if(temp<p.count[j]) <br="">

           {  
               temp=p.count[j] ;  
               k=j ;  
           }  
     }  
     for(j=0;j<p.frame;j++) <br="">

     {  
         if(flag==0 && k==j)  
         {  
           p.curr[j]=page[i] ;  
           p.count[j]=0 ;  
           fault++ ;  
         }  
         else  
         if(j<fault) <br="">         {  
           p.count[j]=0 ;  
           for(s=i+1;s<pages;s++) <br="">           {  
             if(page[i]==p.curr[j])  
             break ;  
             else  
             p.count[j]++ ;  
           }  
         }  
         p.count[j]++;  
         if(p.curr[j]!=-1)  
         printf("\t%d",p.curr[j]) ;  
     }  
     if(flag==0)  
     printf("\t\t\t*") ;  
     printf("\n") ;  
  }  
  printf("no of page fault%d",fault);  
 }

 

Other Projects to Try:

  1. Bankers Algorithm using C Language OS problem
  2. How to Implement Hash Table using C language
  3. Operations on matrices like addition, multiplication, saddle point, magic square ,inverse & transpose
  4. Hash table code in C Language
  5. string operations such as Copy, Length, Reversing, Palindrome, Concatenation

Filed Under: Operating System

Reader Interactions

Comments

  1. Excellent K Kwailane says

    July 6, 2015 at 2:44 pm

    Hello do you have the page replacement algorithms in Visual Basics

    Reply
    • ProjectsGeek says

      July 30, 2015 at 4:32 pm

      You can convert this algorithm into Visual Basics. Just follow the same algorithm in visual basic and then you are good.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy