OUTPUT :
2 -1 -1
2 3 -1
2 3 -1
2 3 1
5 3 1
5 2 1
5 2 4
5 2 4
3 2 4
3 2 4
3 5 4
3 5 2
Number of page faults : 6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #include<stdio.h> #include<conio.h> int fr[3]; void main() { void display(); int i,j,page[12]={2,3,2,1,5,2,4,5,3,2,5,2}; int flag1=0,flag2=0,pf=0,frsize=3,top=0; clrscr(); for(i=0;i<3;i++) { fr[i]=-1; } for(j=0;j<12;j++) { flag1=0; flag2=0; for(i=0;i<12;i++) { if(fr[i]==page[j]) { flag1=1; flag2=1; break; } } if(flag1==0) { for(i=0;i<frsize;i++) { if(fr[i]==-1) { fr[i]=page[j]; flag2=1; break; } } } if(flag2==0) { fr[top]=page[j]; top++; pf++; if(top>=frsize) top=0; } display(); } printf("Number of page faults : %d ",pf); getch(); } void display() { int i; printf("\n"); for(i=0;i<3;i++) printf("%d\t",fr[i]); } |
OUTPUT :
2 -1 -1
2 3 -1
2 3 -1
2 3 1
5 3 1
5 2 1
5 2 4
5 2 4
3 2 4
3 2 4
3 5 4
3 5 2
Number of page faults : 6
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Submit #Terms of Use
Copyright©2011 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com | Powered by Dhyeya
January 30th, 2010 at 6:15 pm
can you give me C Program for clock page replacement Algorithm?
November 18th, 2010 at 10:43 am
this code is not working……… here page faults are 9 but u say 6.
December 5th, 2010 at 10:09 pm
the code in line 18 is wrong……
the correct code will be
for(i=0;i<3;i++)
February 15th, 2011 at 10:33 pm
can uplz give me the algorithm steps for scheduling algorithms(fcfs,sjf,priority,round robin0
and also for page replacement algorithms(fifo,lru)
April 8th, 2011 at 5:06 pm
plz send mai fcfs and roud robib
April 10th, 2011 at 1:14 pm
can i get java code????
May 6th, 2011 at 10:30 am
@ankit: first learn properly,then only comment,,page faults are 6..it is corect
August 16th, 2011 at 4:24 pm
hey yr prog is giving page fault as 6
but if u manually calculate it u will find it is 9
September 6th, 2011 at 3:25 pm
program is not correct
November 3rd, 2011 at 5:41 pm
it is very good effort ,keep it up
November 9th, 2011 at 7:28 am
Here fr[3] means there will b 4 frames i.e.,0,1,2,3 so thats y we r getting 6 as page faults
November 15th, 2011 at 12:10 am
actually different books give different info for calculation of page faults..
here first 3 page faults ( ie wen frame is empty or partially empty ) are not considered..
November 18th, 2011 at 11:32 pm
incorrect code
December 17th, 2011 at 12:06 pm
thankyou
January 30th, 2012 at 3:21 pm
@prachi you are correct
January 31st, 2012 at 10:18 pm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OS_lab___FIFO
{
class Program
{
static void Main(string[] args)
{
int[] fr_mainMemory = new int[3];
int i,j;
int [] page={2,3,2,1,5,2,4,5,3,2,5,2};
int flag1=0,flag2=0,pf=0,frsize=3,top=0;
Console.WriteLine(“\n\n\t\t***BEHAVIOUR OF FIFO PAGE REPLACEMENT ALGORITHM***\n\n”);
Console.WriteLine(“These are pages in resident set having fixed frame allocation size of 3 frames\n\n”);
Console.WriteLine(“\tPage Address Stream : “);
for (i = 0; i < 12; i++)
{
Console.Write(" "+page[i]+" ");
}
Console.WriteLine("\n\n");
for(i=0;i<3;i++)
{
fr_mainMemory[i]=-1;
}
for(j=0;j<12;j++)
{
flag1=0;
flag2=0;
for(i=0;i<frsize;i++)
{
if(fr_mainMemory[i]==page[j])
{
flag1=1;
flag2=1;
break;
}
}
if(flag1==0)
{
for(i=0;i=frsize)
top=0;
}
display(fr_mainMemory);
}
Console.WriteLine(“\tNumber of page faults : “+pf);
}
static void display(int [] f)
{
int i;
int[] residentset = new int[3];
int frsize = 3;
for (i = 0; i < frsize; i++)
{
residentset[i] = f[i];
}
for (i = 0; i < frsize; i++)
{
Console.Write("\t"+residentset[i]+" ");
}
Console.WriteLine("\n");
}
}
}
January 31st, 2012 at 10:19 pm
its the correct code and it works