Write a program in C that simulates a page frame replacement algorithm. Main mem
ID: 3935308 • Letter: W
Question
Write a program in C that simulates a page frame replacement algorithm.
Main memory consists of 16 page frames.
1.) generate a linked list of at least 1000 random numbers greater than
or equal to 0 and less than 64.
2.) make copy of the list of numbers and cull adjacent numbers that are
equal. Your culled list should end up with at least 1000 numbers, so your
unculled list will have greater than 1000.
3.) simulate
a.) FIFO (First in First out) algorithm
first page in is the first to be swapped out
second page in is the second to be swapped out
etc.
b.) optimal algorithm
scan list of pages to be brought in and select the one that won’t be used for the longest time.
Run the optimal and FIFO algorithms for your original list and the culled list.
4.) Report your page fault percentage.
Explanation / Answer
1)
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
/* given data structure declaration */
struct record {
int data;
struct record * next;
};
typedef struct record RecordType;
/* DO NOT MODIFY */
/* print a list */
void print_list(RecordType * list)
{
RecordType * visitor = list;
int count = 0;
while (visitor != NULL)
{
printf("%d ", visitor->data);
visitor = visitor->next;
count++;
}
printf(" ");
printf("There are %d items in the list. ", count);
}
/* MY WORK HERE */
/* free every node in the list */
void free_list(RecordType * list)
{
while (list->data != 2){
free(list->next);
list->next = list;
}
}
/* MY WORK HERE */
/* this function may call other functions created by students */
/* create a list storing all prime numbers in [1, 1000] in ascending order */
/* return a pointer to the starting point of the list */
RecordType * create_list_prime_in_1_to_1000()
{
RecordType * begin, *tail, *temp;
int i = 0;
begin = malloc(sizeof(RecordType));
begin->data = 0;
begin->next = NULL;
tail = begin;
while(i<1000){
temp = malloc(sizeof(RecordType));
temp -> data = ++i;
tail -> next = temp;
tail -> temp;
tail -> next = NULL;
}
}
int isPrime(int n){
int d;
for (d = 2; d < n; d = d + 1)
if (n % d == 0)
return 0;
return 1;
}
3)a
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.