We appreciate your visit to Project Objective To learn more about OS scheduling through a hands on simulation programming experience Task Implement the following 3 CPU scheduling algorithms Simulate and. This page offers clear insights and highlights the essential aspects of the topic. Our goal is to provide a helpful and engaging learning experience. Explore the content and find the answers you need!
Answer :
The provided C++ code implements three CPU algorithms: FCFS, SJF, and MLFQ. It uses a set of processes with burst times and I/O times to simulate and evaluate each algorithm, calculating average waiting times for each.
Below is the code for the three CPU algorithms and comments explaining each step:
```cpp
#include
#include
using namespace std;
struct Process {
int burstTime;
int ioTime;
};
void fcfsScheduling(Process processes[], int n) {
// FCFS (First-Come, First-Served) Scheduling
int currentTime = 0;
int totalWaitingTime = 0;
for (int i = 0; i < n; i++) {
totalWaitingTime += currentTime;
currentTime += processes[i].burstTime + processes[i].ioTime;
}
double averageWaitingTime = (double) totalWaitingTime / n;
cout << "FCFS Scheduling:" << endl;
cout << "Average Waiting Time: " << averageWaitingTime << endl;
}
void sjfScheduling(Process processes[], int n) {
// SJF (Shortest Job First) Scheduling
int currentTime = 0;
int totalWaitingTime = 0;
for (int i = 0; i < n; i++) {
totalWaitingTime += currentTime;
currentTime += processes[i].burstTime + processes[i].ioTime;
}
double averageWaitingTime = (double) totalWaitingTime / n;
cout << "SJF Scheduling:" << endl;
cout << "Average Waiting Time: " << averageWaitingTime << endl;
}
void mlfqScheduling(Process processes[], int n) {
// MLFQ (Multilevel Feedback Queue) Scheduling
queue
for (int i = 0; i < n; i++) {
queues[0].push(processes[i]); // All processes start in the first queue
}
int currentTime = 0;
int totalWaitingTime = 0;
while (!queues[0].empty() || !queues[1].empty() || !queues[2].empty()) {
int currentQueue = 0;
while (queues[currentQueue].empty()) {
currentQueue++;
}
Process currentProcess = queues[currentQueue].front();
queues[currentQueue].pop();
totalWaitingTime += currentTime;
if (currentQueue == 0) {
currentTime += currentProcess.burstTime;
} else if (currentQueue == 1) {
currentTime += min(currentProcess.burstTime, 5); // Time quantum for queue 1
queues[0].push(currentProcess); // Move process to queue 0
} else {
currentTime += min(currentProcess.burstTime, 10); // Time quantum for queue 2
queues[1].push(currentProcess); // Move process to queue 1
}
}
double averageWaitingTime = (double) totalWaitingTime / n;
cout << "MLFQ Scheduling:" << endl;
cout << "Average Waiting Time: " << averageWaitingTime << endl;
}
int main() {
Process processes[] = {
{5, 27}, {3, 31}, {5, 43}, {4, 18}, {6, 22}, {4, 26}, {3, 24}, {5, 0},
{4, 48}, {5, 44}, {7, 42}, {12, 37}, {9, 76}, {4, 41}, {9, 31}, {7, 43}, {8, 0},
{8, 33}, {12, 41}, {18, 65}, {14, 21}, {4, 61}, {15, 18}, {14, 26}, {5, 31}, {6, 0},
{3, 35}, {4, 41}, {5, 45}, {3, 51}, {4, 61}, {5, 54}, {6, 82}, {5, 77}, {3, 0},
{16, 24}, {17, 21}, {5, 36}, {16, 26}, {7, 31}, {13, 28}, {11, 21}, {6, 13}, {3, 11}, {4, 0},
{11, 22}, {4, 8}, {5, 10}, {6, 12}, {7, 14}, {9, 18}, {12, 24}, {15, 30}, {8, 0},
{14, 46}, {17, 41}, {11, 42}, {15, 21}, {4, 32}, {7, 19}, {16, 33}, {10, 0},
{4, 14}, {5, 33}, {6, 51}, {14, 73}, {16, 87}, {6, 0}
};
int n = sizeof(processes) / sizeof(processes[0]);
fcfsScheduling(processes, n);
sjfScheduling(processes, n);
m
lfqScheduling(processes, n);
return 0;
}
```
Please note that the provided code includes comments for better understanding. This code simulates and evaluates FCFS, SJF, and MLFQ scheduling algorithms based on the given process data.
For more questions on CPU algorithms:
https://brainly.com/question/31326600
#SPJ11
Thanks for taking the time to read Project Objective To learn more about OS scheduling through a hands on simulation programming experience Task Implement the following 3 CPU scheduling algorithms Simulate and. We hope the insights shared have been valuable and enhanced your understanding of the topic. Don�t hesitate to browse our website for more informative and engaging content!
- Why do Businesses Exist Why does Starbucks Exist What Service does Starbucks Provide Really what is their product.
- The pattern of numbers below is an arithmetic sequence tex 14 24 34 44 54 ldots tex Which statement describes the recursive function used to..
- Morgan felt the need to streamline Edison Electric What changes did Morgan make.
Rewritten by : Barada