OSY EXP 15

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

OSY EXP 15 Hawaiza Siddiqui 19431

Program Code :
Q1) Implement FIFO Page Replacement algorithm on following Page Reference Stream:
1 2 3 2 1 5 2 1 6 2 5 6 3 1 3 6 1 2 4 3
CODE:
#include<stdio.h>
int main(){
int reference_string[10], page_faults = 0, m, n, s, pages, frames;
printf("\nHawaiza Siddiqui 19431\t");
printf("\nEnter Total Number of Pages:\t");
scanf("%d", &pages);
printf("\nEnter values of Reference String:\n");
for(m = 0; m < pages; m++){
printf("Value No. [%d]:\t", m + 1);
scanf("%d", &reference_string[m]); }
printf("\nEnter Total Number of Frames:\t");
scanf("%d", &frames);
int temp[frames];
for(m = 0; m < frames; m++){
temp[m] = -1;}
for(m = 0; m < pages; m++){
s = 0;
for(n = 0; n < frames; n++){
if(reference_string[m] == temp[n]){
s++;
page_faults--; }}
page_faults++;
if((page_faults <= frames) && (s == 0)){
temp[m] = reference_string[m];}
else if(s == 0)
temp[(page_faults - 1) % frames] = reference_string[m];
printf("\n");
for(n = 0; n < frames; n++)
{
printf("%d\t", temp[n]);
}
}
printf("\nTotal Page Faults:\t%d\n", page_faults);
return 0;
}
OUTPUT:
OSY EXP 15 Hawaiza Siddiqui 19431

You might also like