SlideShare a Scribd company logo
1 of 3
#include <stdio.h>
int findLRU(int time[], int n)
{
int i, minimum = time[0], pos = 0;
for (i = 1; i < n; ++i)
{
if (time[i] < minimum)
{
minimum = time[i];
pos = i;
}
}
return pos;
}
//main function
int main()
{
int f, n, frames[10], pages[30], counter = 0, time[10], flag1, flag2, i, j, pos, faults = 0, count=0,
k, avail,ch;
char h[10]="hit", pf[10]="fault";
printf("Enter number of frames: ");
scanf("%d", &f);
printf("Enter number of pages: ");
scanf("%d", &n);
printf("Enter reference string: ");
for (i = 0; i < n; ++i)
{
scanf("%d", &pages[i]);
}
printf(" select the Page replacement algorithm:n 1. LRU n 2.FIFO n");
printf("enter your choice:");
scanf("%d", &ch);
switch(ch)
{
case 1:
for (i = 0; i < f; ++i)
{
frames[i] = -1;
}
for (i = 0; i < n; ++i)
{
flag1 = flag2 = 0;
for (j = 0; j < f; ++j)
{
if (frames[j] == pages[i])
{
counter++;
time[j] = counter;
flag1 = flag2 = 1;
break;
}
}
if (flag1 == 0)
{
for (j = 0; j < f; ++j)
{
if (frames[j] == -1)
{
counter++;
faults++;
frames[j] = pages[i];
time[j] = counter;
flag2 = 1;
break;
}
}
}
if (flag2 == 0)
{
pos = findLRU(time, f);
counter++;
faults++;
frames[pos] = pages[i];
time[pos] = counter;
}
printf("n");
for (j = 0; j < f; ++j)
{
printf("%dt", frames[j]);
}
}
printf("nTotal Page Faults = %d", faults);
break;
case 2:
for(i=0;i<f;i++)
frames[i]= -1;
j=0;
printf("tref stringt page framesn");
for(i=0;i<n;i++)
{
printf("%dtt",pages[i]);
avail=0;
for(k=0;k<f;k++)
if(frames[k]==pages[i])
{
avail=1;
for(k=0;k<f;k++)
printf("%dt",frames[k]);
}
if (avail==0)
{
frames[j]=pages[i];
j=(j+1)%f;
count++;
for(k=0;k<f;k++)
printf("%dt",frames[k]);
}
printf("n");
}
printf("Page Fault Is %d",count);
break;
default: printf("invalid coicen");
break;
}
return 0;
}

More Related Content

Similar to Lab9 LRU and FIFO.docx

#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf
arjunchetri1
 
Programs for Operating System
Programs for Operating SystemPrograms for Operating System
Programs for Operating System
LPU
 
Sorting programs
Sorting programsSorting programs
Sorting programs
Varun Garg
 
C basics
C basicsC basics
C basics
MSc CST
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
HIMANSUKUMAR12
 

Similar to Lab9 LRU and FIFO.docx (20)

#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf
 
Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programs
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
 
Programs for Operating System
Programs for Operating SystemPrograms for Operating System
Programs for Operating System
 
Bankers Algo Implementation
Bankers Algo ImplementationBankers Algo Implementation
Bankers Algo Implementation
 
Structure
StructureStructure
Structure
 
Structure
StructureStructure
Structure
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
Array Programs.pdf
Array Programs.pdfArray Programs.pdf
Array Programs.pdf
 
Sorting programs
Sorting programsSorting programs
Sorting programs
 
SaraPIC
SaraPICSaraPIC
SaraPIC
 
Operating system labs
Operating system labsOperating system labs
Operating system labs
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Vcs29
Vcs29Vcs29
Vcs29
 
C basics
C basicsC basics
C basics
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
week-5x
week-5xweek-5x
week-5x
 

Recently uploaded

Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 

Recently uploaded (20)

A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 

Lab9 LRU and FIFO.docx

  • 1. #include <stdio.h> int findLRU(int time[], int n) { int i, minimum = time[0], pos = 0; for (i = 1; i < n; ++i) { if (time[i] < minimum) { minimum = time[i]; pos = i; } } return pos; } //main function int main() { int f, n, frames[10], pages[30], counter = 0, time[10], flag1, flag2, i, j, pos, faults = 0, count=0, k, avail,ch; char h[10]="hit", pf[10]="fault"; printf("Enter number of frames: "); scanf("%d", &f); printf("Enter number of pages: "); scanf("%d", &n); printf("Enter reference string: "); for (i = 0; i < n; ++i) { scanf("%d", &pages[i]); } printf(" select the Page replacement algorithm:n 1. LRU n 2.FIFO n"); printf("enter your choice:"); scanf("%d", &ch); switch(ch) { case 1: for (i = 0; i < f; ++i) { frames[i] = -1; }
  • 2. for (i = 0; i < n; ++i) { flag1 = flag2 = 0; for (j = 0; j < f; ++j) { if (frames[j] == pages[i]) { counter++; time[j] = counter; flag1 = flag2 = 1; break; } } if (flag1 == 0) { for (j = 0; j < f; ++j) { if (frames[j] == -1) { counter++; faults++; frames[j] = pages[i]; time[j] = counter; flag2 = 1; break; } } } if (flag2 == 0) { pos = findLRU(time, f); counter++; faults++; frames[pos] = pages[i]; time[pos] = counter; } printf("n"); for (j = 0; j < f; ++j)
  • 3. { printf("%dt", frames[j]); } } printf("nTotal Page Faults = %d", faults); break; case 2: for(i=0;i<f;i++) frames[i]= -1; j=0; printf("tref stringt page framesn"); for(i=0;i<n;i++) { printf("%dtt",pages[i]); avail=0; for(k=0;k<f;k++) if(frames[k]==pages[i]) { avail=1; for(k=0;k<f;k++) printf("%dt",frames[k]); } if (avail==0) { frames[j]=pages[i]; j=(j+1)%f; count++; for(k=0;k<f;k++) printf("%dt",frames[k]); } printf("n"); } printf("Page Fault Is %d",count); break; default: printf("invalid coicen"); break; } return 0; }