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]
8 months 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]8 months 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
Read the following scenario: A project will require more people than originally estimated. Identify the possible risks to the pr
egoroff_w [7]
A ideas and creativity
8 0
3 years ago
Read 2 more answers
Why would an online survey of 2,000 visitors to your college’s Web site be of little use in assessing the neighboring community’
musickatia [10]

Answer: the sample is not representative of the community.

Explanation:

Online surveys or surveys in general are made to obtain relevant information about a particular issue. If samples are not representative of that issue, they end up having little use.  

4 0
3 years ago
You are most likely to use<br> images for photos or digital paintings.
Lubov Fominskaja [6]

Answer: Digital Paintings

7 0
3 years ago
Plllzzzzzzzzzzzzzz annnssswweeweerrr...
s2008m [1.1K]

Answer:

An example of effective communication is when the person who you are talking to listens actively and absorbs your point and understands it.

Explanation:

Hope this helps!!

3 0
3 years ago
What is the term for a male reproductive cell?​
prohojiy [21]

Answer:

I believe it is a sperm cell.

Explanation:

Not a sex cell because that can apply to both female and male reproduction.

4 0
3 years ago
Other questions:
  • Being able to express your thoughts in an email is a primary technology skill. True or False
    8·2 answers
  • Which of the following is a true statement? Question 33 options: Data entities correspond to sources/sinks on a data flow diagra
    14·1 answer
  • What is the communications activity of the Internet called
    15·1 answer
  • What is the role of the osi application layer? provides control of all the data flowing between the source and destination devic
    5·1 answer
  • Which port-authentication network access control standard forces devices to go through a full authentication, authorization, and
    13·1 answer
  • If Asa changes the text to bold, he has changed the style. True False
    8·2 answers
  • Is it possible to have a deadlock involving only oneprocess? Explain your answer.
    11·1 answer
  • This is your data.
    11·2 answers
  • Complete the following sentence.
    12·1 answer
  • The ______ process retains copies of data over extended periods of time in order to meet legal and operational requirements.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!