#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

PDF
Os lab upto_1st_mid
PDF
Os lab 1st mid
PDF
Os lab upto 1st mid
PDF
InsertionSort.pdf
DOC
Daapracticals 111105084852-phpapp02
PDF
Additional_Solutions_TPEC _datastrucures.pdf
PDF
codes.txt.pdf code presentation engineering
PDF
C Prog - Pointers
Os lab upto_1st_mid
Os lab 1st mid
Os lab upto 1st mid
InsertionSort.pdf
Daapracticals 111105084852-phpapp02
Additional_Solutions_TPEC _datastrucures.pdf
codes.txt.pdf code presentation engineering
C Prog - Pointers

Similar to Lab9 LRU and FIFO.docx (20)

DOCX
DAA Lab File C Programs
PDF
Unix Programs
PDF
#include stdio.h #include stdlib.h #include time.hdouble.pdf
DOCX
Os lab file c programs
PDF
PCA-2 Programming and Solving 2nd Sem.pdf
DOCX
PCA-2 Programming and Solving 2nd Sem.docx
TXT
Programs for Operating System
 
TXT
Bankers Algo Implementation
PPTX
Structure
PPTX
Structure
PDF
COgdfgdffgdgfgdasdasdaffadadsdsd5ANS.pdf
PDF
22-SE-77 OS_lab_labotary assignmnet#2.pdf
PPTX
L25-L26-Parameter passing techniques.pptx
PDF
Array Programs.pdf
DOC
Sorting programs
DOCX
SaraPIC
DOCX
Operating system labs
DOCX
DOC
C basics
DAA Lab File C Programs
Unix Programs
#include stdio.h #include stdlib.h #include time.hdouble.pdf
Os lab file c programs
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.docx
Programs for Operating System
 
Bankers Algo Implementation
Structure
Structure
COgdfgdffgdgfgdasdasdaffadadsdsd5ANS.pdf
22-SE-77 OS_lab_labotary assignmnet#2.pdf
L25-L26-Parameter passing techniques.pptx
Array Programs.pdf
Sorting programs
SaraPIC
Operating system labs
C basics
Ad

Recently uploaded (20)

PPTX
Feature types and data preprocessing steps
PPTX
CyberSecurity Mobile and Wireless Devices
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PPTX
introduction to high performance computing
PDF
August 2025 - Top 10 Read Articles in Network Security & Its Applications
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PPTX
Current and future trends in Computer Vision.pptx
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
Design Guidelines and solutions for Plastics parts
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPTX
Information Storage and Retrieval Techniques Unit III
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
Feature types and data preprocessing steps
CyberSecurity Mobile and Wireless Devices
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
introduction to high performance computing
August 2025 - Top 10 Read Articles in Network Security & Its Applications
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
Current and future trends in Computer Vision.pptx
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
Design Guidelines and solutions for Plastics parts
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Information Storage and Retrieval Techniques Unit III
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
distributed database system" (DDBS) is often used to refer to both the distri...
Ad

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; }