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
What is the unofficial name given to the culture that has emerged from living in the age of digital media, whereby people are fr
gizmo_the_mogwai [7]
The digital age has grown to a point that it permeates every area of our day to day lives. It is known to directly affect our ability to concentrate ... and smartphones in particular, with constant incoming notifications from various sources of interest that are always within reach, present a particularly powerful and consistent distraction. Therefore, I would say that "culture of distraction" is an apt descriptor.
4 0
4 years ago
Read 2 more answers
Write a function that takes as input a single parameter storing a list of integers and returns the minimum, maximum, and average
Alex Ar [27]

Answer:

hi im coolkid 1000

Explanation:

just 5 robuk

6 0
3 years ago
You have one IP address provided from your ISP with a /30 mask. However, you have 300 users that need to access the Internet. Wh
DedPeter [7]

Answer:

A. PAT.

Explanation:

Based on the detail given the technology I will

basically use to help implement the solution will be PAT which full meaning is PORT ADDRESS TRANSLATION reason been that PAT is a technology that enables multiple users to have access to the internet and secondly PORT ADDRESS TRANSLATION (PAT) can often share one IP public address to multiple or different internet users at a time.

8 0
3 years ago
This elementary problem begins to explore propagation delay and transmission delay, two central concepts in data networking. Con
puteri [66]

Answer:

Explanation:

Solution

a)

The "bit" is just leaving "Host A"

b)

The 1st bit is in the link and has not reached "Host B"

c)

The 1st bit has reached "Host B"

6 0
4 years ago
In what way, if any, is a model different from a simulation?
madam [21]

Answer:

Models and Simulations are completely different in that they achieve diffenet results.

Explanation:

Modeling is the act of building a model. A simulation is the process of using a model to study the behavior and performance of an actual or theoretical system. In a simulation, models can be used to study existing or proposed characteristics of a system. ... Simulating is the act of using a model for a simulation.

6 0
3 years ago
Other questions:
  • Write a function "hailstone"that takes an int "n2"and prints the hailstone sequence. Hailstone Numbers:This sequence takes the n
    15·1 answer
  • Colleen is creating a document with two minimal paragraphs of text comparing two business models for her company. She decides to
    14·2 answers
  • Computer a has an overall cpi of 1.3 and can be run at a clock rate of 600mhz. computer b has a cpi of 2.5 and can be run at a c
    11·1 answer
  • When you set the position property for a block element to absolute, the browser?
    8·1 answer
  • Given the following code:
    7·1 answer
  • How do you recognize the brand name of a drug in the package insert?
    15·1 answer
  • What is the definition of D1-D4?
    14·1 answer
  • Give one advantage of saving file in the same folder<br>​
    13·2 answers
  • How are computers connected to one another?
    5·2 answers
  • Write the text of the program in Python.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!