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 #Resources #Terms of Use
Copyright©2012 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com
can you give me C Program for clock page replacement Algorithm?
this code is not working……… here page faults are 9 but u say 6.
the code in line 18 is wrong……
the correct code will be
for(i=0;i<3;i++)
can uplz give me the algorithm steps for scheduling algorithms(fcfs,sjf,priority,round robin0
and also for page replacement algorithms(fifo,lru)
plz send mai fcfs and roud robib
can i get java code????
@ankit: first learn properly,then only comment,,page faults are 6..it is corect
hey yr prog is giving page fault as 6
but if u manually calculate it u will find it is 9
program is not correct
it is very good effort ,keep it up
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
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..
incorrect code
thankyou
@prachi you are correct
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");
}
}
}
its the correct code and it works
import java.util.*;
import java.io.*;
class marks
{
public static void main(String args[])
{
double SGPA,CGPA;
char ch;
DataInputStream dis = new DataInputStream(System.in);
System.out.println(“enter your choice:”);
System.out.println(“s1->semester1″);
System.out.println(“s2->semester2″);
System.out.println(“s3->semester3″);
System.out.println(“ch—>”);
System.out.flush();
try
{
switch(ch=(char)System.in.read())
{
case ‘s1′:
System.out.println(“English language skills”);
int M[0]=Integer.parseInt(in.readLine());
System.out.println(“Engg.mathematics-1″);
int M[1]=Integer.parseInt(in.readLine());
System.out.println(“engg.physics-1″);
int M[2]=Integer.parseInt(in.readLine());
System.out.println(“Engg chemistry-1″);
int M[3]=Integer.parseInt(in.readLine());
System.out.println(“programming with c”);
int M[4]=Integer.parseInt(in.readLine());
System.out.println(“programming with clab”);
int M[5]=Integer.parseInt(in.readLine());
System.out.println(“engg.chemistry lab”);
int M[6]=Integer.parseInt(in.readLine());
System.out.println(“EE wrokshop lab”);
int M[7]=Integer.parseInt(in.readLine());
if(M[0]<40||M[1]<40||M[2]<40||M[3]<40||M[4]<40||
M[5]<40||M[6]<40||M[7]<40)
{
System.out.println("FAILED");
else
switch(ch)
{
for(int i=0;i90)
part[i]=credit[i]*10;
case 2:if(M[i]>80||M[i]70||M[i]60||M[i]50||M[i]40||M[i]<49)
part[i]=credit[i]*5;
}while(ch<=6)
import java.util.*;
import java.lang.*;
import java.io.DataInputStream;
class Marks
{
public static void main(String args[])
{
System.out.println(“1->Semester1″);
int E[]=new int[8];
int part[]=new int[8];
int grade=0;
int Credit[]={3,4,4,4,3,2,2,2};
int E2[]=new int[9];
int part2[]=new int[9];
int grade2=0;
int Credit2[]={3,3,3,3,3,3,2,2,2};
int E3[]=new int[9];
int part3[]=new int[9];
int grade3=0;
int Credit3[]={3,4,3,4,3,3,2,2,2};
float sgp=0,sgp2=0,sgp3=0,cgpa=0,total=0,total2=0,total3=0;
try
{ System.out.println(“Enter ur marks in 1st sem in serial order”);
System.out.println(“English marks”);
System.out.println(“Maths1″);
System.out.println(“Physics”);
System.out.println(“chemistry1″);
System.out.println(“C”);
System.out.println(“C lab”);
System.out.println(“chemistry lab”);
System.out.println(“EE lab”);
DataInputStream in=new DataInputStream(System.in);
for(int i=0;i<E.length;i++)
{
E[i]=Integer.parseInt(in.readLine());
}
}
catch(Exception e)
{
System.out.println("Error");
System.exit(1);
}
if(E[0]<40||E[1]<40||E[2]<40||E[3]<40||E[4]<40||E[5]<40||E[6]<40||E[7]<40)
{
System.out.println("Student failed in 1st sem");
grade=1;
}
else
{
for(int i=0;i=90)
part[i]=Credit[i]*10;
else if(E[i]>=80)
part[i]=Credit[i]*9;
else if(E[i]>=70)
part[i]=Credit[i]*8;
else if(E[i]>=60)
part[i]=Credit[i]*7;
else if(E[i]>=50)
part[i]=Credit[i]*6;
else if(E[i]>=40)
part[i]=Credit[i]*5;
}
}
for(int i=0;i<E.length;i++)
{
total=total+part[i];
sgp=total/24;
}
System.out.println("Student's sgp in 1st sem is"+sgp);
try
{System.out.println("2-Semester2");
System.out.println("Enter ur marks in 2nd sem in serial order");
System.out.println("English marks");
System.out.println("Maths2");
System.out.println("Maths3");
System.out.println("Physics2");
System.out.println("chemistry2");
System.out.println("C++");
System.out.println("Physics lab");
System.out.println("C++lab");
System.out.println("Graphics lab");
DataInputStream in=new DataInputStream(System.in);
for(int i=0;i<E2.length;i++)
{
E2[i]=Integer.parseInt(in.readLine());
}}
catch(Exception e)
{
System.out.println("Error");
System.exit(1);
}
if(E2[0]<40||E2[1]<40||E2[2]<40||E2[3]<40||E2[4]<40||E2[5]<40||E2[6]<40||E2[7]<40)
{
System.out.println("Student failed in 2nd sem");
grade2=1;
}
else
{
for(int i=0;i=90)
part2[i]=Credit2[i]*10;
else if(E2[i]>=80)
part2[i]=Credit2[i]*9;
else if(E2[i]>=70)
part2[i]=Credit2[i]*8;
else if(E2[i]>=60)
part2[i]=Credit2[i]*7;
else if(E2[i]>=50)
part2[i]=Credit2[i]*6;
else if(E2[i]>=40)
part2[i]=Credit2[i]*5;
}
}
for(int i=0;i<E2.length;i++)
{
total2=total2+part2[i];
sgp2=total2/24;
}
System.out.println("Student's sgp in 2nd sem is"+sgp2);
try
{ System.out.println("Enter ur marks in 3rd sem in serial order");
System.out.println("Basic electronics");
System.out.println("Environmental");
System.out.println("Dms");
System.out.println("DS");
System.out.println("PSQT");
System.out.println("FDL");
System.out.println("DS lab");
System.out.println("Electronics lab");
System.out.println("English lab");
DataInputStream in=new DataInputStream(System.in);
for(int i=0;i<E3.length;i++)
{
E3[i]=Integer.parseInt(in.readLine());
}}
catch(Exception e)
{
System.out.println("Error");
System.exit(1);
}
if(E3[0]<40||E3[1]<40||E3[2]<40||E3[3]<40||E3[4]<40||E3[5]<40||E3[6]<40||E3[7]<40)
{
System.out.println("Student failed in 3rd sem");
grade3=1;
}
else
{
for(int i=0;i=90)
part3[i]=Credit3[i]*10;
else if(E3[i]>=80)
part3[i]=Credit3[i]*9;
else if(E3[i]>=70)
part3[i]=Credit3[i]*8;
else if(E3[i]>=60)
part3[i]=Credit3[i]*7;
else if(E3[i]>=50)
part3[i]=Credit3[i]*6;
else if(E3[i]>=40)
part3[i]=Credit3[i]*5;
}
}
for(int i=0;i<E3.length;i++)
{
total3=total3+part3[i];
sgp3=total3/26;
}
System.out.println("Student's sgp in 3rd sem is"+sgp3);
cgpa=(((sgp*24)+(sgp2*24)+(sgp3*26))/74);
System.out.println("Student's cgpa is"+cgpa);
}
}
I try to run the first programme through the DevC++ compiler and it doesn’t running (lot of errors)
toooo booring i m gonna sleep after doing this
can ani one help me ….”Write a program that implements the FIFO page- replacement algorithms.First, generate a random page reference string where page numbers range from 0 to 9. Apply the random page-reference string to each algorithm. Implement the replacement algorithms so that the number of page frames can vary from 1 to 7. Assume that demand paging is used. “
anyone help me to write java coding for working set clock page replacement algorithm