Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Do the following problem with he following modification: You may use any of the

ID: 3763829 • Letter: D

Question

Do the following problem with he following modification: You may use any of the following languages for your program: C, C++, Java.                                                                                                                                           The random page-refrence string should consist of at least 10000 numbers. Using the same reference string, obtain the number of faults for each algorithm (FIFO and LRU) for each of the following number of page frames: 1, 2, 3, 4, 5, 6, 7, 8.    

Your solution is expected to be a complete program that runs to completion.

Plot a graph of page fault frequency (y-axis) versus number of page frames (x-axis). Draw both plots on the same graph. Label each plot by the algorithm identifer (FIFO, LRU). Note: it is not expected that your program will produce the plot; rather, a seperate application can be used to make the plot.                                                                                    

Write a Program that implements the FIFO and LRU page-replacement algorithms presented in his Chapter. First, generate a random page-refrence string where page numbers range from 0 o 9. Apply the random page-reference string to each algorithm, and record the number of page faults incurred by each algorithm. Implement the replacement algorithms so that the number of page frames can vary as well. Assume that depend paging is used.

Explanation / Answer

FIFO page repalacement algorithm treats page frames allocated to process as a circular buffer.

When the buffer is full the oldest page has to replace,that is first in first out.

     c program to implement FIFO page replacement algorithm

#include<stdio.h>

int main()

{

int i,j,n,a[50],frame[10],no,k,avail,count=0;

            printf(" ENTER THE NUMBER OF PAGES: ");

scanf("%d",&n);

            printf(" ENTER THE PAGE NUMBER : ");

            for(i=1;i<=n;i++)

            scanf("%d",&a[i]);

            printf(" ENTER THE NUMBER OF FRAMES :");

            scanf("%d",&no);

for(i=0;i<no;i++)

            frame[i]= -1;

                        j=0;

                        printf(" ref string page frames ");

for(i=1;i<=n;i++)

                        {

                                    printf("%d ",a[i]);

                                    avail=0;

                                    for(k=0;k<no;k++)

if(frame[k]==a[i])

                                                avail=1;

                                    if (avail==0)

                                    {

                                                frame[j]=a[i];

                                                j=(j+1)%no;

                                                count++;

                                                for(k=0;k<no;k++)

                                                printf("%d ",frame[k]);

}

                                    printf(" ");

}

                        printf("Page Fault Is %d",count);

                        return 0;

}

LRU: Least recently used page replacement algorithm.In this replaces the page that has not been used for longest time

c program to implement LRU page replacement algorithm

#include<stdio.h>

main()

{

int a[20],b[50],c=0,c1,d,f,i,j,k=0,n,r,t,p[20],c2[20];

printf("Enter no of pages:");

scanf("%d",&n);

printf("Enter the reference string:");

for(i=0;i<n;i++)

            scanf("%d",&b[i]);

printf("Enter no of frames:");

scanf("%d",&f);

a[k]=b[k];

printf(" %d ",q[k]);

c++;

k++;

for(i=1;i<n;i++)

            {

                        c1=0;

                        for(j=0;j<f;j++)

                        {

                                    if(b[i]!=a[j])

                                    c1++;

                        }

                        if(c1==f)

                        {

                                    c++;

                                    if(k<f)

                                    {

                                                a[k]=b[i];

                                                k++;

                                                for(j=0;j<k;j++)

                                                printf(" %d",a[j]);

                                                printf(" ");

                                    }

                                    else

                                    {

                                                for(r=0;r<f;r++)

                                                {

                                                            c2[r]=0;

                                                            for(j=i-1;j<n;j--)

                                                            {

                                                            if(a[r]!=b[j])

                                                            c2[r]++;

                                                            else

                                                            break;

                                                }

                                    }

                                    for(r=0;r<f;r++)

                                     p[r]=c2[r];

                                    for(r=0;r<f;r++)

                                    {

                                                for(j=r;j<f;j++)

                                                {

                                                            if(p[r]<p[j])

                                                            {

                                                                        t=p[r];

                                                                        p[r]=p[j];

                                                                        p[j]=t;

                                                            }

                                                }

                                    }

                                    for(r=0;r<f;r++)

                                    {

                                                if(c2[r]==b[0])

                                                a[r]=b[i];

                                                printf(" %d",a[r]);

                                    }

                                    printf(" ");

                        }

            }

}

printf(" The no of page faults is %d",c);

}

Here iam giving with sample for FIFO

for example the reference string is:1,2,3,4,1,2,5,1,2,3,4,5

3 frames(3 pages can be at a time in memory at a time per process): 1 1-4-5

2 2-1-3

3 3-2-4

here page faults is 9

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote