1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Karolina [17]
1 year ago
12

and assuming main memory is initially unloaded, show the page faulting behavior using the following page replacement policies. h

ow many page faults are generated by each page replacement algorithm?
Computers and Technology
1 answer:
Svet_ta [14]1 year ago
4 0

FIFO

// C++ implementation of FIFO page replacement

// in Operating Systems.

#include<bits/stdc++.h>

using namespace std;

// Function to find page faults using FIFO

int pageFaults(int pages[], int n, int capacity)

{

   // To represent set of current pages. We use

   // an unordered_set so that we quickly check

   // if a page is present in set or not

   unordered_set<int> s;

   // To store the pages in FIFO manner

   queue<int> indexes;

   // Start from initial page

   int page_faults = 0;

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

   {

       // Check if the set can hold more pages

       if (s.size() < capacity)

       {

           // Insert it into set if not present

           // already which represents page fault

           if (s.find(pages[i])==s.end())

           {

               // Insert the current page into the set

               s.insert(pages[i]);

               // increment page fault

               page_faults++;

               // Push the current page into the queue

               indexes.push(pages[i]);

           }

       }

       // If the set is full then need to perform FIFO

       // i.e. remove the first page of the queue from

       // set and queue both and insert the current page

       else

       {

           // Check if current page is not already

           // present in the set

           if (s.find(pages[i]) == s.end())

           {

               // Store the first page in the

               // queue to be used to find and

               // erase the page from the set

               int val = indexes.front();

               

               // Pop the first page from the queue

               indexes.pop();

               // Remove the indexes page from the set

               s.erase(val);

               // insert the current page in the set

               s.insert(pages[i]);

               // push the current page into

               // the queue

               indexes.push(pages[i]);

               // Increment page faults

               page_faults++;

           }

       }

   }

   return page_faults;

}

// Driver code

int main()

{

   int pages[] = {7, 0, 1, 2, 0, 3, 0, 4,

               2, 3, 0, 3, 2};

   int n = sizeof(pages)/sizeof(pages[0]);

   int capacity = 4;

   cout << pageFaults(pages, n, capacity);

   return 0;

}

LRU

//C++ implementation of above algorithm

#include<bits/stdc++.h>

using namespace std;

// Function to find page faults using indexes

int pageFaults(int pages[], int n, int capacity)

{

   // To represent set of current pages. We use

   // an unordered_set so that we quickly check

   // if a page is present in set or not

   unordered_set<int> s;

   // To store least recently used indexes

   // of pages.

   unordered_map<int, int> indexes;

   // Start from initial page

   int page_faults = 0;

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

   {

       // Check if the set can hold more pages

       if (s.size() < capacity)

       {

           // Insert it into set if not present

           // already which represents page fault

           if (s.find(pages[i])==s.end())

           {

               s.insert(pages[i]);

               // increment page fault

               page_faults++;

           }

           // Store the recently used index of

           // each page

           indexes[pages[i]] = i;

       }

       // If the set is full then need to perform lru

       // i.e. remove the least recently used page

       // and insert the current page

       else

       {

           // Check if current page is not already

           // present in the set

           if (s.find(pages[i]) == s.end())

           {

               // Find the least recently used pages

               // that is present in the set

               int lru = INT_MAX, val;

               for (auto it=s.begin(); it!=s.end(); it++)

               {

                   if (indexes[*it] < lru)

                   {

                       lru = indexes[*it];

                       val = *it;

                   }

               }

               // Remove the indexes page

               s.erase(val);

               // insert the current page

               s.insert(pages[i]);

               // Increment page faults

               page_faults++;

           }

           // Update the current page index

           indexes[pages[i]] = i;

       }

   }

   return page_faults;

}

// Driver code

int main()

{

   int pages[] = {7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2};

   int n = sizeof(pages)/sizeof(pages[0]);

   int capacity = 4;

   cout << pageFaults(pages, n, capacity);

   return 0;

}

You can learn more about this at:

brainly.com/question/13013958#SPJ4

You might be interested in
In 2009 to 2010, how many social network users were reported as being victims of online abuse?
Dafna1 [17]
The answer is B because being victims of online abuse is not important
7 0
3 years ago
Read 2 more answers
A slide _____ is a special animation effect used to progress from one slide to the next slide in a slide show.
Nutka1998 [239]
A slide *transition* is the word you're looking for, well I mean, if you're using powerpoint it is.
8 0
4 years ago
Read 2 more answers
What is the famous saying among computer programmers?
USPshnik [31]
The famous saying is garbage in , garbage out .
3 0
4 years ago
PLEASE HELP ASAP I WILL MARK AS BRILLIANT
Natali [406]
1) Irresponsible behavior.
2) Using a password-protected website and making sure only specific friends can see it.<span>
</span>3) Posting offensive pictures is disrespectful of the feelings of others.
4) Mark posts his e-mail address to gain access to a dozen online gambling sites.
6 0
3 years ago
HELP I NEED IT RIGHT NOW. I'LL MARK YOU THE BRAINLIEST. Each of these citations contains at least one mistake. Identify the prob
Tema [17]

Answer:

See explanation for full answer

Explanation:

Here are the new citations:

1)Vadukul, A. (2017, May 14). Driftwood Haiku on the Bronx Riviera. The New York Times, p. 1.

To fix this citation in APA the first name should be the first initial, the date should be second typed in yyyy,month dd in paranthesis. The title of the article is not in quotes and the name of the newspaper goes in italics

2) Silverstein, S. (2017). Where the Sidewalk Ends: Poems and Drawings. New York,NY: HarperCollins.

To fix this citation in APA the first name is full last name, first initial. The year the book is published is next in paranthesis followed by where the publishing company is located and then the state and city. The last part is the publishing companies name

3)Rilke, R. M., & Snell, R. (2004). Letters to a young poet (917507652 721002613 M. H. Norton, Trans.). Mineola, NY: Dover Publications.

To fix this citation in APA the authors full last name and initials go first followed by the year the book was published in paranthesis. The title of the book goes next and if you have it the ISBN with the translator. The publishing company city,state then the publication company name.

4) Emerson, R. W., & Porte, J. (2003). The Poet in Nature and Selected Essays. New York, NY: Penguin House.

To fix this citation in APA again the authors names have to be last name and first initial. The year the book was published follows. Then the title of the book in italics. Followed by the information for the publishing company (city,state,publishing company title)

Hope this helps you!

6 0
3 years ago
Other questions:
  • (GAME DESIGN)
    15·1 answer
  • Assuming arrayName is the name of an array and identifier is a name of a variable that has the same data type as the array eleme
    6·1 answer
  • Frank has created a résumé and separated the sections using headings. How can he set the headings apart from normal text?
    13·1 answer
  • Driving while wearing headphones or earphones
    12·2 answers
  • (50 points) Write a program arrays1.cthat checks if two integer arrays are different by one and only one elementwhen compared el
    5·1 answer
  • .Write a C++ program that displays your name and address (if you value your privacy, a fictitious name and address).
    9·1 answer
  • Question :
    6·1 answer
  • Does anyone know what i did wrong?
    13·1 answer
  • Rewrite the Espresso Counter program to Swap or interchange any two rows of the output. Copy and paste just the interchanged par
    14·1 answer
  • For a web application we associate a web server, for a mobile application we associate a mobile server. for a decentralized appl
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!