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
dangina [55]
3 years ago
9

Write a program that implements the FIFO and LRU page-replacement algorithms learned in class. First, generate a random page ref

erence string where page numbers range from 0 to 9. Then, 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 from 1 to 7. Assume demand paging is used.
Computers and Technology
1 answer:
erastova [34]3 years ago
3 0

Answer:

Code implemented using C++ below

Explanation:

sambswas

answered this

#include<iostream>

#include<cstdlib>

#define CYCLES 100

using namespace std;

struct page_table_entry {

int page_num;

int last_access_time;

int first_access_time;

};

int num_of_frames;

int sequence;

struct page_table_entry *page_table;

void init() {

page_table = new page_table_entry[num_of_frames];

for (int i = 0; i < num_of_frames; i++) {

page_table[i].page_num = -1;

page_table[i].first_access_time = -1;

page_table[i].last_access_time = -1;

}

sequence = 0;

}

int get_random_page() {

sequence++;

return rand() % 10;

}

int request_frame_LRU() {

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

if (page_table[i].page_num == -1) {

cout << "Empty frame found at location " << i << endl;

return i;

}

int target = 0;

for (int i = 1; i < num_of_frames; i++)

if (page_table[i].last_access_time < page_table[target].last_access_time)

target = i;

cout << "target frame is " << target << ", containing page " << page_table[target].page_num << endl;

return target;

}

int request_frame_FIFO() {

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

if (page_table[i].page_num == -1){

cout << "Empty frame found at location " << i << endl;

return i;

}

int target = 0;

for (int i = 1; i < num_of_frames; i++)

if (page_table[i].first_access_time < page_table[target].first_access_time)

target = i;

cout << "target frame is " << target << ", containing page " << page_table[target].page_num << endl;

return target;

}

int search_page(int page) {

for (int i = 0; i < num_of_frames; i++) {

if (page_table[i].page_num == -1)

continue;

if (page_table[i].page_num == page) {

cout << "page " << page << " found at location " << i << endl;

return i;

}

}

cout << "page " << page << " not found" << endl;

return -1;

}

void LRU() {

init();

int miss = 0;

int hit = 0;

for (int i = 0; i < CYCLES; i++) {

int page = get_random_page();

cout << "Requested page is: " << page << endl;

int location = search_page(page);

if (location > 0) {

page_table[location].last_access_time = sequence;

hit ++;

}

else {

location = request_frame_LRU();

page_table[location].page_num = page;

page_table[location].first_access_time = sequence;

page_table[location].last_access_time = sequence;

miss++;

}

cout << endl;

}

double hit_ratio = (double)hit/(hit+miss);

cout << "######## LRU ########" << endl;

cout << "hits: " << hit << endl;

cout << "misses: " << miss << endl;

cout << "hit ratio: " << hit_ratio << endl;

cout << "for frame size " << num_of_frames << endl;

cout << "#######################" << endl << endl;

}

void FIFO() {

init();

int miss = 0;

int hit = 0;

for (int i = 0; i < CYCLES; i++) {

int page = get_random_page();

cout << "Requested page is: " << page << endl;

int location = search_page(page);

if (location > 0) {

page_table[location].last_access_time = sequence;

hit ++;

}

else {

location = request_frame_FIFO();

page_table[location].page_num = page;

page_table[location].first_access_time = sequence;

page_table[location].last_access_time = sequence;

miss++;

}

cout << endl;

}

double hit_ratio = (double)hit/(hit+miss);

cout << "######## FIFO ########" << endl;

cout << "hits: " << hit << endl;

cout << "misses: " << miss << endl;

cout << "hit ratio: " << hit_ratio << endl;

cout << "for frame size " << num_of_frames << endl;

cout << "#######################" << endl << endl;

}

int main() {

srand(time(NULL));

num_of_frames = rand() % 7 + 1;

LRU();

FIFO();

}

You might be interested in
Software that enables you to display and interact with text and other media on the web is a web ________.
a_sh-v [17]
It's a web site or web page
5 0
4 years ago
How is Tesla manufacturing different from any other manufacturing?
stealth61 [152]

Answer:

Tesla’s arent vehicles needing gas, so they dont have a fuel tank, instead they have a charging port.

Explanation:

4 0
3 years ago
The term "net radiation" refers to _____ the total amount of energy received by earth. the total amount of energy radiated by ea
Nimfa-mama [501]

The term "net radiation" refers to <span>the difference in amount of incoming and outgoing radiation the total amount of energy received by earth.
</span>
<span>Energy comes from the sunlight penetrates the top of the atmosphere- that's the incoming energy. Then some of it is lost by reflection of clouds or the Earth's surface, thermal radiation- that's the outgoing energy.</span>

5 0
3 years ago
Which technologies allows multiple applications to execute in isolated user spaces, share the same operating system kernel, and
coldgirl [10]

Answer:

OS-level virtualization

Explanation:

OS-level virtualization in cloud infrastructure allows the division and full utilization of resources of one hardware allowing it to run more than one or multiple operating system. With this technology, each operating system is dedicated to one user space instance called a virtual machine, and each user space is independent of other operating systems or user space instances in the kernel such that the failure of one operating system does not affect others.

8 0
3 years ago
System software is software that allows users to do things like create text documents, play games, listen to music or web browse
hoa [83]

Answer:

False

Explanation:

System software is the collection of programs that controls and manage the operation of a computer.

5 0
3 years ago
Other questions:
  • A tool you might use to manipulate an image, such as a photograph, into a seamless repeating texture would be:
    7·2 answers
  • What should you do first to best use your personal goals as a means for a promotion?
    13·1 answer
  • The undo function allows the user to cancel up to _____ previous typing actions
    15·2 answers
  • I need some help with ideas
    15·1 answer
  • Plymouth Colony was originally founded by a group of people called Pilgrims. Since Plymouth did not have an official charter fro
    15·1 answer
  • Return a version of the given string, where for every star (*) in the string the star and the chars immediately to its left and
    11·1 answer
  • Can you please help look at the picture i will give you a. brainliest and 10 points​
    15·2 answers
  • Need the answer ASAP!!!
    14·1 answer
  • A bubble starts by comparing the first item in the list to all the remaining items, and swaps where the first item is ____ a lat
    9·2 answers
  • Write the code to produce a for loop that counts down from 20 to 0 by 2’s and prints the number each time it goes through the lo
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!