Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

virtual.c CSCI-SHU MISC|very useful during revision

Rating
-
Sold
-
Pages
9
Grade
A+
Uploaded on
07-12-2022
Written in
2022/2023

#include "oslabs.h" #include stdio.h #include string.h #include stdbool.h // 1 int process_page_access_fifo(struct PTE page_table[TABLEMAX],int *table_cnt, int page_number, int frame_pool[POOLMAX],int *frame_cnt, int current_timestamp) { // first checks if the page being referenced is already in memory (i.e., the page-table entry has the valid bit true) if (page_table[page_number].is_valid == true) { // modifies the last_access_timestamp page_table[page_number].last_access_timestamp = current_timestamp; // and the reference_count fields of the page-table entry page_table[page_number].reference_count += 1; // returns the total number of page faults encountered in the simulation return page_table[page_number].frame_number; // checks if there are any free frames (i.e., the process frame pool is not empty) } else if ((page_table[page_number].is_valid == false) && (*frame_cnt 0)) { // a frame is removed from the process frame pool *frame_cnt -= 1; // the frame number is inserted into the page-table entry corresponding to the logical page number page_table[page_number].frame_number = frame_pool[*frame_cnt-1]; // the other fields of the page-table entry are set appropriately page_table[page_number].is_valid = true; page_table[page_number].last_access_timestamp = current_timestamp; page_table[page_number].reference_count = 1; // returns the total number of page faults encountered in the simulation return page_table[page_number].frame_number; // If the page being referenced is not in memory and there are no free frames for the process, a page needs to be replaced. } else { bool temp_flag = false; int temp_index = 0; int temp_frame = 0; int temp_arrival_stemp = 0

Show more Read less
Institution
Course

Content preview

#include "oslabs.h"
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
// 1
int process_page_access_fifo(struct PTE page_table[TABLEMAX],int *table_cnt, int page_number, int frame_pool[POOLMAX],int *frame_cnt, int current_timestamp) { // first checks if the page being referenced is already in memory (i.e., the page-table entry has the valid bit true) if (page_table[page_number].is_valid == true) { // modifies the last_access_timestamp page_table[page_number].last_access_timestamp = current_timestamp; // and the reference_count fields of the page-table entry page_table[page_number].reference_count += 1; // returns the total number of page faults encountered in the simulation return page_table[page_number].frame_number; // checks if there are any free frames (i.e., the process frame pool is not empty) } else if ((page_table[page_number].is_valid == false) && (*frame_cnt > 0)) { // a frame is removed from the process frame pool *frame_cnt -= 1; // the frame number is inserted into the page-table entry corresponding to the logical page number page_table[page_number].frame_number = frame_pool[*frame_cnt-1]; // the other fields of the page-table entry are set appropriately page_table[page_number].is_valid = true; page_table[page_number].last_access_timestamp = current_timestamp; page_table[page_number].reference_count = 1; // returns the total number of page faults encountered in the simulation return page_table[page_number].frame_number; // If the page being referenced is not in memory and there are no free frames for the process, a page needs to be replaced. } else { bool temp_flag = false; int temp_index = 0; int temp_frame = 0; int temp_arrival_stemp = 0; // The function selects among all the pages of the process that are currently
in memory (i.e., they have valid bits as true) // the page that has the smallest arrival_timestamp. for (int index = 0; index < *table_cnt ; index++) { if ((page_table[index].is_valid == true) && (temp_flag== false)) { temp_index = index; temp_frame = page_table[index].frame_number; temp_arrival_stemp = page_table[index].arrival_timestamp; temp_flag = true; } else if ((page_table[index].is_valid == true) && (temp_arrival_stemp > page_table[index].arrival_timestamp) && (temp_flag== true)) { temp_arrival_stemp = page_table[index].arrival_timestamp; temp_index = index; temp_frame = page_table[index].frame_number; } } // It marks that page-table entry as invalid, along with setting the arrival_timestamp, last_access_timestamp and reference_count to 0. // It then sets the frame_number of the page-table entry of the newly-This study source was downloaded by 100000857840091 from CourseHero.com on 12-07-2022 03:27:51 GMT -06:00
https://www.coursehero.com/file/102607567/virtualc/ referenced page to the newly freed frame. // It also sets the arrival_timestamp, the last_access_timestamp and the reference_count fields of the page-table entry appropriately. if (temp_flag == true) { page_table[temp_index].is_valid = false; page_table[temp_index].arrival_timestamp = 0; page_table[temp_index].last_access_timestamp = 0; page_table[temp_index].reference_count = 0; page_table[temp_index].frame_number = -1; page_table[page_number].arrival_timestamp = current_timestamp; page_table[page_number].last_access_timestamp = current_timestamp; page_table[page_number].frame_number = temp_frame; page_table[page_number].reference_count = 1; page_table[page_number].is_valid = true; } // returns the total number of page faults encountered in the simulation return temp_frame; }
}
// 2 - determines the memory frame number for the logical page and returns this number
int count_page_faults_fifo(struct PTE page_table[TABLEMAX],int table_cnt, int refrence_string[REFERENCEMAX],int reference_cnt,int frame_pool[POOLMAX],int frame_cnt) { // set timestamp and frame number int timestamp = 1, page_fault = 0; for (int i = 0; i < reference_cnt; i++) { // checks if the page being referenced is already in memory (i.e., the page-
table entry has the valid bit true) if (page_table[refrence_string[i]].is_valid == true) { // returns the frame number, after modifying the last_access_timestamp and
the reference_count fields of the page-table entry page_table[refrence_string[i]].last_access_timestamp = timestamp; page_table[refrence_string[i]].reference_count += 1; // If the page being referenced is not in memory, the function checks if there are any free frames (i.e., the process frame pool is not empty) } else if ((page_table[refrence_string[i]].is_valid == false) && (frame_cnt >
0)) { // a frame is removed from the process frame pool frame_cnt -= 1; page_fault += 1; // and the frame number is inserted into the page-table entry corresponding to the logical page number page_table[refrence_string[i]].frame_number = frame_pool[frame_cnt-1]; // the other fields of the page-table entry are set appropriately page_table[refrence_string[i]].is_valid = true; page_table[refrence_string[i]].last_access_timestamp = timestamp; page_table[refrence_string[i]].reference_count += 1; // If the page being referenced is not in memory and there are no free frames
for the process, a page needs to be replaced } else if ((page_table[refrence_string[i]].is_valid == false) && (frame_cnt == 0)) { page_fault += 1; bool temp_flag = false; int temp_index = 0; int temp_frame = 0;This study source was downloaded by 100000857840091 from CourseHero.com on 12-07-2022 03:27:51 GMT -06:00
https://www.coursehero.com/file/102607567/virtualc/

Written for

Institution
Course

Document information

Uploaded on
December 7, 2022
Number of pages
9
Written in
2022/2023
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$6.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Abbyy01 Exam Questions
Follow You need to be logged in order to follow users or courses
Sold
96
Member since
4 year
Number of followers
33
Documents
1337
Last sold
1 week ago

3.5

13 reviews

5
5
4
2
3
3
2
1
1
2

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions