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
Which print setting enables multiple slides to be printed on one page?
seraphim [82]
Handouts
see the image for reference

3 0
3 years ago
Read 2 more answers
If num is an int which expression always evaluates to true if num holds an odd number
kherson [118]

num%2==1

The modulo operator (%) divides the left hand side by the right hand side and returns the remainder. When dividing an odd number by 2 there will always be a remainder of 1.

8 0
4 years ago
Which option allows you to link to a specific slide in another presentation?
tresset_1 [31]
The power-point option for new slide. or maybe duplicate slide.
3 0
4 years ago
Which option is an appropriate database function syntax?
kodGreya [7K]

Answer:

=DSUM(A4:D8, "Unit Cost", A1:B2)

Explanation:

From the list of given options, it's obvious that the question relates to Excel database sum function.

The correct answer among the list of options is:

=DSUM(A4:D8, "Unit Cost", A1:B2)

Where

DSUM represents the function itself

A4:D8 represents the range

"Unit cost" represents the field

and

A1:B2 represents the criteria of the function

Analysing other options:

Option 1: The equality sign (=) before excel formulas is missing

Option 2: Sum is used instead of DSUM and there's a missing bracket before the range

Option 3: There's a missing comma between the range, the field and the criteria

Hence, the last option (4) answers the question.

5 0
3 years ago
Read 2 more answers
Alison is having a hard time at work because her Inbox is flooded with emails every day. Some of these emails are unsolicited. S
fredd [130]

Answer:

1.c 2.a

Explanation:

If the new emails she doesn't need could be ignored in spam. the old ones are useless so trash em.

5 0
3 years ago
Read 2 more answers
Other questions:
  • Type the correct answer in the box. Spell all words correctly.
    12·1 answer
  • A user prefers an external monitor, mouse, and keyboard for a laptop. The user does not want to use the built-in screen; however
    5·1 answer
  • A variable of the data type arrays is storing 10 quantities. What is true about these quantities?
    10·1 answer
  • _____ is an effort by an employee to attract attention to a negligent, illegal, unethical, abusive, or dangerous act by a compan
    8·1 answer
  • Consider a Rational class designed to represent rational numbers as a pair of ints, along with methods reduce (to reduce the rat
    10·1 answer
  • _____ is a method of computing that delivers secure, private, and reliable computing experiences based on sound business practic
    7·1 answer
  • How can a user restore a message that was removed from the Deleted Items folder?
    10·1 answer
  • Which type of project data would you review for an accurate picture of the project progress and labor costs
    8·1 answer
  • Your computer science teacher asks you to sample a black and white image that is 4” x 6”. How would you sample the image to prov
    10·1 answer
  • Help fast pleas. 3. How is this text formatted? (1 point)
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!