0% found this document useful (0 votes)
8 views

8FIFO

This document describes a First In First Out (FIFO) page replacement algorithm. It takes in the number of frames and page sizes as input. It checks if the page is already in the frame using a found() function. If not found, it uses a freefound() function to find an empty frame and replaces the oldest page. It prints the frames after each page fault and the total number of page faults.

Uploaded by

Harshita Gopu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

8FIFO

This document describes a First In First Out (FIFO) page replacement algorithm. It takes in the number of frames and page sizes as input. It checks if the page is already in the frame using a found() function. If not found, it uses a freefound() function to find an empty frame and replaces the oldest page. It prints the frames after each page fault and the total number of page faults.

Uploaded by

Harshita Gopu
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

First In First Out(FIFO)

#include<stdio.h> #include<conio.h> int c,p,i,j,sz[20],frame[20],t=0,x; int found(int x); int freefound(); main() { static int pf,k; clrscr(); printf("Enter no.of frames"); scanf("%d",&p); for(i=0;i<p;i++) frame[i]=-1; printf("Enter sizes of pages"); for(i=0;;i++) { scanf("%d",&sz[i]); if(sz[i]==-1) break; c=c+1; } for(i=0;i<c;i++) { if(found(sz[i])) continue; x=freefound(); if(x!=-1) frame[x]=sz[i]; else { frame[t]=sz[i]; t=(t+1)%p; } pf=pf+1; printf("\nThe values present in frame= "); for(k=0;k<p;k++) if(frame[k]!=-1) printf("%d",frame[k]); } printf("\nThe total no.of page faults are%d",pf); printf("Enter the value"); scanf("%d",&i); } int found(int x) { int j; for(j=0;j<p;j++) if(frame[j]==x)

return 1; return 0; } int freefound() { int i; for(i=0;i<p;i++) if(frame[i]==-1) return i; return -1; } RESULT: Input:Enter no.of frames 3 Enter sizes of pages 2 3 2 1 5 2 4 5 3 2 5 2 -1 Output: The values present in frame=2 The values present in frame=2 The values present in frame=2 The values present in frame=5 The values present in frame=5 The values present in frame=5 The values present in frame=3 The values present in frame=3 The values present in frame=3 The total number of page faults

3 3 3 2 2 2 5 5 are

1 1 1 4 4 4 2 9

You might also like