Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE ASSIST ASAP, MANY STUDENTS ARE IN NEED OF THIS AND WILL UPVOTE IF CORRECT, C PROGRAMMING LANGUAGE ******This question regards to building off of

PLEASE ASSIST ASAP, MANY STUDENTS ARE IN NEED OF THIS AND WILL UPVOTE IF CORRECT, C PROGRAMMING LANGUAGE

******This question regards to building off of and adding to base code provided below, in order to achieve the expected outcome*****

- Please only complete in C programming from scratch ( NOT C++)

- Please see all parts and follow the rubric/guidelines

- Please provide the full, entire, combined, and modified program as the answer ( no fragments please)

- Please ensure it runs properly with no errors

- Please ensure the code/answer provides the same output as needed and expected

THANK YOU GREATLY !!!! I REALLY APPRECIATE IT

*********Assignment Scope: Page Replacement (background information)***********

1. First In First Out: FIFO algorithm replaces the oldest (first) page which has been present for the longest time in the main memory. When a new page comes in from secondary memory to main memory, it selects the front of the queue which is the oldest page present, and removes it.

1. Least Recently Used: Least Recently Used (LRU) page replacement algorithm works on the concept that the pages that are heavily used in previous instructions are likely to be used heavily in next instructions. The pages that are used the least are likely to be used the least in future and are replaced. Page fault occurs when a referenced page is not found in the memory frames. Whenever a page fault occurs, the page that is least recently used is removed from the memory frames.

****** BASE CODE TO BUILD OFF OF/MODIFY/COMBINE******

#include

#include

#include

// Global Constants

#define EXIT 0

#define INVALID -1

#define MEMORY 1

#define FILES 2

#define THREAD 3

#define FIRST 0

#define BEST 1

#define WORST 2

#define NEXT 3

// Function prototypes

int displayMenu();

void clearScreen();

void memoryManagement();

void displayProcess(int allocation[], int processes, int processSize[]);

void firstFit(int blockSize[], int blocks, int processSize[], int processes);

void worstFit(int blockSize[], int blocks, int processSize[], int processes);

void bestFit(int blockSize[], int blocks, int processSize[], int processes);

void nextFit(int blockSize[], int blocks, int processSize[], int processes);

int main(void) {

int choice = -1;

printf("********** Operating System Management Menu ********** ");

while (choice != 0) {

choice = displayMenu();

if (choice == 1) {

// memoryManagement

memoryManagement();

} else if (choice == 2) {

// fileManagement

printf("Error, not found ");

printf("********** Operating System Management Menu ********** ");

} else if (choice == 3) {

// multiThreads

printf("Error, not found ");

printf("********** Operating System Management Menu ********** ");

} else {

exit(0);

}

}

return 0;

}

// print the menu

int displayMenu() {

int choice = -1;

while (choice == -1) {

printf("\t1. Memory Management ");

printf("\t2. File Management ");

printf("\t3. MultiThreading ");

printf("\t0. Exit ");

scanf("%d", &choice);

}

if (choice >= 0 && choice <= 3) {

return choice;

} else {

choice = -1;

return choice;

}

return 0;

}

// the function below clears the screen.

void clearScreen() {

char enter;

printf(" Hit the Enter button to continue. ");

scanf("%c", &enter);

// Windows

// system("cls");

// Mac & Linux

system("clear");

}

// the function below will clear the screen, and then construct 4 arrays, and

// then use decision based logic to call the appropriate fit function.

void memoryManagement() {

clearScreen();

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

int blockSize[5] = {80, 10, 65, 35, 70};

int processSize[5] = {25, 70, 5, 45, 60};

int blocks = 5;

int processes = 5;

switch (i) {

case FIRST:

printf("\t\t********** First Fit ********** ");

firstFit(blockSize, blocks, processSize, processes);

break;

case BEST:

printf("\t\t********** Best Fit ********** ");

bestFit(blockSize, blocks, processSize, processes);

break;

case WORST:

printf("\t\t********** Worst Fit ********** ");

worstFit(blockSize, blocks, processSize, processes);

break;

case NEXT:

printf("\t\t********** Next Fit ********** ");

nextFit(blockSize, blocks, processSize, processes);

break;

}

}

}

// the function below mimics how FirstFit works.

void firstFit(int blockSize[], int blocks, int processSize[], int processes) {

int allocation[processes];

memset(allocation, INVALID, sizeof(allocation));

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

for (int j = 0; j < blocks; j++) {

if (blockSize[j] >= processSize[i]) {

allocation[i] = j + 1;

blockSize[j] -= processSize[i];

break;

}

}

}

displayProcess(allocation, processes, processSize);

}

// the function below mimics how Best Fit works.

void bestFit(int blockSize[], int blocks, int processSize[], int processes) {

int allocation[processes];

memset(allocation, INVALID, sizeof(allocation));

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

int bestIdx = INVALID;

for (int j = 0; j < blocks; j++) {

if (blockSize[j] >= processSize[i]) {

if (bestIdx == INVALID) {

bestIdx = j;

} else if (blockSize[bestIdx] > blockSize[j]) {

bestIdx = j;

}

}

}

if (bestIdx != INVALID) {

allocation[i] = bestIdx + 1;

blockSize[bestIdx] -= processSize[i];

}

}

displayProcess(allocation, processes, processSize);

}

// the function below mimics how Worst Fit works.

void worstFit(int blockSize[], int blocks, int processSize[], int processes) {

int allocation[processes];

memset(allocation, INVALID, sizeof(allocation));

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

int wstIdx = INVALID;

for (int j = 0; j < blocks; j++) {

if (blockSize[j] >= processSize[i]) {

if (wstIdx == INVALID) {

wstIdx = j;

} else if (blockSize[wstIdx] < blockSize[j]) {

wstIdx = j;

}

}

}

if (wstIdx != INVALID) {

allocation[i] = wstIdx + 1;

blockSize[wstIdx] -= processSize[i];

}

}

displayProcess(allocation, processes, processSize);

}

// the function below mimics how next Fit works.

void nextFit(int blockSize[], int blocks, int processSize[], int processes) {

int allocation[processes];

int id = 0;

memset(allocation, INVALID, sizeof(allocation));

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

while (id < blocks) {

if (blockSize[id] >= processSize[i]) {

allocation[i] = id + 1;

blockSize[id] -= processSize[i];

break;

}

id = (id + 1) % blocks;

}

}

displayProcess(allocation, processes, processSize);

}

// the function below will display the results.

void displayProcess(int allocation[], int processes, int processSize[]) {

printf("Process no.\t\tProcess Size.\t\tBlock No.");

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

printf(" %d\t\t\t\t%d", i + 1, processSize[i]);

if (allocation[i] == -1) {

printf("\t\t\t\tNot Allocated ");

} else {

printf("\t\t\t\t\t%d ", allocation[i]);

}

}

}

****** DELIVERABLES TO CODE INTO BASE CODE ******

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Explain about operations on Data Structure?

Answered: 1 week ago

Question

Which of the following strait separate north america from Asia ?

Answered: 1 week ago