100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
virtual.c CSCI-SHU MISC|very useful during revision $6.49   Add to cart

Exam (elaborations)

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

 21 views  0 purchase

#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 b...

[Show more]

Preview 2 out of 9  pages

  • December 7, 2022
  • 9
  • 2022/2023
  • Exam (elaborations)
  • Questions & answers
All documents for this subject (2)
avatar-seller
Abbyy01
#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/

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller Abbyy01. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $6.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

79079 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$6.49
  • (0)
  Add to cart