Question

In: Computer Science

Write a program that implements the FIFO, LRU, and Optimal page replacement algorithms presented in chapter...

Write a program that implements the FIFO, LRU, and Optimal page replacement algorithms presented in chapter 8 of your text. First generate a random page-reference string (this should be 20 entries long) where page numbers range from 0 to 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 goes from 1 to 7 and you must compute the page fault for each of these frame numbers. Record the number of page faults with each of these different page frames numbers and each of the different algorithms. Assume that demand paging is used. Remember to count the first time a page comes in, as this is a page fault in demand paging. Then do the same procedure, except use the following page-reference string instead of the random one: 0,7,0,1,2,0,8,9,0,3,0,4,5,6,7,0,8,9,1,2 and then lastly do it with the page-reference string: 7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1 The sample output has the correct solutions for LRU and FIFO but nothing for Optimal. Have separate clearly marked classes, functions, or methods for LRU, FIFO, and Optimal replacement algorithms. Also have comments within your code. Make certain to have your name, date, assignment number, and a brief description of the program at the top of your main method. Your output should be in the following format (repeated seven times, one for each number of page frames, and the set of seven repeated three times, one for each of the three page-reference strings): For x page frames, and using string page reference string nnnnnnnnnnnnnn: FIFO had ### page faults. LRU had ### page faults. Optimal had ### page faults. Where ### is the number of page faults, x is the number of page frames, and nnnnnn is the page-reference string.

Solutions

Expert Solution

  • LRU CODE:

    #include<stdio.h>
    #include<conio.h>
    #define max 25
    
    void main()
    {
    int frame[10],used[10],index;
    int i,j,k,nf,np=0,page[max],temp;
    int flag=0,pf=0;
    clrscr();
    printf("Enter no. of Frames:");
    scanf("%d",&nf);
    for(i=0;i<nf;i++)
    frame[i]=-1;
    printf("Enter pages (press -999 to exit):\n");
    for(i=0;i<max;i++)
    {
    scanf("%d",&temp);
    if(temp==-999) break;
    page[i]=temp;
    np++;
    }
    for(i=0;i<np;i++)
    {
    flag=0;
    for(j=0;j<nf;j++)
    {
    if(frame[j]==page[i])
    {
    printf("\n\t");
    flag=1;break;
    }
    }
    if(flag==0)
    {
    for(j=0;j<nf;j++) used[j]=0;
    for(j=0,temp=i-1;j<nf-1;j++,temp--)
    {
    for(k=0;k<nf;k++)
    {
    if(frame[k]==page[temp])
    used[k]=1;
    }
    }
    for(j=0;j<nf;j++)
    if(used[j]==0)
    index=j;
    frame[index]=page[i];
    printf("\nFault: ");
    pf++;
    }
    for(k=0;k<nf;k++)
    printf("%d\t",frame[k]);
    }
    printf("\nNumber of page faults is: %d ",pf);
    getch();
    }

    FIFO CODE

    #include<stdio.h>
    
    int main()
    
    {
    
    int i,j,n,a[50],frame[10],no,k,avail,count=0;
    
                printf("\n ENTER THE NUMBER OF PAGES:\n");
    
    scanf("%d",&n);
    
                printf("\n ENTER THE PAGE NUMBER :\n");
    
                for(i=1;i<=n;i++)
    
                scanf("%d",&a[i]);
    
                printf("\n ENTER THE NUMBER OF FRAMES :");
    
                scanf("%d",&no);
    
    for(i=0;i<no;i++)
    
                frame[i]= -1;
    
                            j=0;
    
                            printf("\tref string\t page frames\n");
    
    for(i=1;i<=n;i++)
    
                            {
    
                                        printf("%d\t\t",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\t",frame[k]);
    
    }
    
                                        printf("\n");
    
    }
    
                            printf("Page Fault Is %d",count);
    
                            return 0;
    
    }
    Let me know if you have any doubts or if you need anything to change. 
    
    If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.
    
    Thank You!
    ===========================================================================

Related Solutions

P3 – Page Replacement Algorithms CS3310 Operating Systems Page Replacement: Complete the program that implements the...
P3 – Page Replacement Algorithms CS3310 Operating Systems Page Replacement: Complete the program that implements the FIFO and LRU algorithms presented in the chapter and calculates the number of page faults generated given a particular reference string. Implement the replacement algorithms such that the number of page frames can vary. Assume that demand paging is used. Required Modifications: Implement LRU and FIFO algorithms Add appropriate data structures and private helper methods to LRU.h and FIFO.h Implement the insert() method in...
Optimal and near-optimal process scheduling and page replacement algorithms. a) What is the theoretically best process...
Optimal and near-optimal process scheduling and page replacement algorithms. a) What is the theoretically best process scheduling algorithm? b) Do shortest job first and shortest remaining time first amount to the same thing or not? c) Can they be directly implemented? d) What do you consider the next best scheduling option, and how does it use the recent past to approximate the ideal case? e) Consider the analogous case in page replacement. What is the best possible choice of page...
Write a C++ program that implements both the recursive binary and mergesort algorithms as described in...
Write a C++ program that implements both the recursive binary and mergesort algorithms as described in zyBooks sections 9.4 and 9.5. Prompt the user for the location of a sequence of numbers, via an external file or data entry by the user. If you choose data entry, prompt the user for the number of values and read them into a data structure of your choice. Then use the mergesort algorithm to sort them in ascending order. Finally, prompt for a...
Task: Write a program that implements several sorting algorithms and use it to demonstrate the comparative...
Task: Write a program that implements several sorting algorithms and use it to demonstrate the comparative performance of the algorithms for a variety of datasets. Background The skeleton program sorting.cpp contains a main function for testing the operation of several sort algorithms over various data sizes and dataset organisations. The program understands the following arguments: -i insertion sort -s selection sort (default) -q quicksort -a (already) sorted dataset -v reverse-sorted dataset -r random dataset (default) -n no sorting x generate...
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called...
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called "vdot" that calculates the "dot product" of two vectors "a" and "b", implemented as “arrays” (following the “C” language convention), of 3 elements. the macro should receive 2 pointers to the first element of each vector and return the result in R13.
Write a program that implements the follow disk scheduling algorithms. You can use C or Java...
Write a program that implements the follow disk scheduling algorithms. You can use C or Java for this assignment. FCFS SSTF SCAN C-SCAN LOOK C-LOOK Your program will service a disk with 5000 cylinders (numbered 0 to 4999). Your program will generate a random initial disk head position, as well as a random series of 1000 cylinder requests, and service them using each of the 6 algorithms listed above. Your program will report the total amount of head movement required...
IN jAVA Language PLEASE Write a JAVA program that implements the following disk-scheduling algorithms: a. FCFS...
IN jAVA Language PLEASE Write a JAVA program that implements the following disk-scheduling algorithms: a. FCFS b. SSTF c. SCAN Your program will service a disk with 5,000 cylinders numbered 0 to 4,999. The program will generate a random series of 50 requests and service them according to each of the algorithms you chose. The program will be passed the initial position of the disk head as a parameter on the command line and report the total amount of head...
Page Replacement Algorithms. Consider the following page reference stream and 3 page frames: 0 1 2...
Page Replacement Algorithms. Consider the following page reference stream and 3 page frames: 0 1 2 3 2 4 3 1 1 5 2 4 6 3 3 4 6 3 4 7. For the MIN, FIFO, and LRU algorithms, show the contents of the page frame after each reference, and then compute the total number of page faults, divided in to cold misses and other misses.
Develop an algorithm and implement Optimal Page Replacement algorithm using C++. Determine the number of page...
Develop an algorithm and implement Optimal Page Replacement algorithm using C++. Determine the number of page faults and page hits by considering the Frame size=4, ReferenceString:2 4 6 7 8 2 4 9 13 9 2 7 2 6 1 4 9 2
1. Chapter 5, Programming Challenge #8, Conversion Program (page 314). Program Name: FinalExamConversion. Write a program...
1. Chapter 5, Programming Challenge #8, Conversion Program (page 314). Program Name: FinalExamConversion. Write a program that asks the user to enter a distance in meters. The program will then present the following menu of selection: 1. Convert to Kilometers 2. Convert to Inches 3. Convert to Feet 4. Quit the Program The program will convert the distance to kilometers, inches or feet, depending on the user’s selection. Write the following methods: • getInput: This method prompts user to enter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT