Objective: Write C programs which implement following page replacement policies.
a) First In First Out (FIFO)
b) Least Recently Used (LRU)
To avoid wasting processor time waiting for an active process to become unblocked. The OS will swap
one of the process out of the main memory to make room for a new process or for a process in
Ready- Suspend state. Therefore, the OS must choose which process to replace. Thus, when a page
fault occurs, the OS has to change a page to remove from memory to make room for the page that
must be brought in. If the page to be removed has been modified while in memory it must be written
to disk to bring the disk copy up to date. Replacement algorithms can affect the system's
performance.
 Replace the page that has been in memory longest, is the policy applied by FIFO. Pages from memory are removed in round-robin fashion. Its advantage is it's simplicity.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],b[20],n,p=0,q=0,m=0,h,k,i,q1=1;
char f='F';
printf("Enter the Number of Pages:");
scanf("%d",&n);
printf("Enter %d Page Numbers:",n);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<n;i++){
if(p==0){
if(q>=3)
q=0;
a[q]=b[i];
q++;
if(q1<3){
q1=q;
}
}
printf("\n%d",b[i]);
printf("\t");
for(h=0;h<q1;h++)
printf("%d",a[h]);
if((p==0)&&(q<=3)){
printf("-->%c",f);
m++;
}
p=0;
for(k=0;k<q1;k++){
if(b[i+1]==a[k])
p=1;
}
}
printf("\nNo of faults:%d",m);
getch();
}
Comments
Leave a comment