Implement the following 3 CPU scheduling algorithms – Simulate and Evaluate each
ID: 3677593 • Letter: I
Question
Implement the following 3 CPU scheduling algorithms –
Simulate and Evaluate each with the set of processes below.
FCFS non-preemptive (results provided)
SJF non-preemptive
MLFQ
Multilevel Feedback Queue (preemptive – absolute priority in higher queues)
Queue 1 uses RR scheduling with Tq = 6
Queue 2 uses RR scheduling with Tq = 11
Queue 3 uses FCFS
All processes enter first queue 1. If time quantum (Tq) expires before CPU burst is complete, the process is downgraded to next lower priority queue. Processes are not downgraded when preempted by a higher queue level process. Once a process has been downgraded, it will not be upgraded.
Assumptions:
All processes are activated at time 0
Assume that no process waits on I/O devices.
After completing an I/O event, a process is transferred to the ready queue.
Waiting time is accumulated while a process waits in the ready queue.
Process Data:
process goes {CPU burst, I/O time, CPU burst, I/O time, CPU burst, I/O time,…….., last CPU burst}
P1 {4,24,5,73,3,31,5,27,4,33,6,43,4,64,5,19,2}
P2 {18,31,19,35,11,42,18,43,19,47,18,43,17,51,19,32,10}
P3 {6,18,4,21,7,19,4,16,5,29,7,21,8,22,6,24,5}
P4 {17,42,19,55,20,54,17,52,15,67,12,72,15,66,14}
P5 {5,81,4,82,5,71,3,61,5,62,4,51,3,77,4,61,3,42,5}
P6 {10,35,12,41,14,33,11,32,15,41,13,29,11}
P7 {21,51,23,53,24,61,22,31,21,43,20}
P8 {11,52,14,42,15,31,17,21,16,43,12,31,13,32,15}
I only need the SJF. Thank you for your time. please do it in c++
Explanation / Answer
If Running: P1 Ready Queue:
Program
#include<iostream>
using namespace std;
struct process{
int processId;
int CPU_burst;
int I/O_Time;
};
int main()
{
int numberOfProcesses;
cout <<"please enter the number of process: ";
cin >> numberOfProcesses;
const int maxprocesses = 10;
struct process p[maxprocesses];
int smallest_burst = p[0].CPU_burst;
int smallest_burst_index = 0;
int smallest_I/O_Time = p[0].I/O_Time;
int smallest_I/O_Time_index = 0;
for(int i=0; i<numberOfProcesses; i++){
p[i].processId = i;
cout << "p" << i << ":" << endl;
cout <<"Burst time: ";
cin >> p[i].CPU_burst;
cout <<"Arrival Time: ";
cin >> p[i].I/O_Time;
}
cout<<"Process" << " " << "Burst" << " " << "Arrival" << endl;
for(int i=0;i<numberOfProcesses;i++){
cout <<"P" << p[i].processId << " " << p[i].CPU_burst << " " << p[i].I/O_Time <<endl;
}
for(int i = 1; i < numberOfProcesses; ++i)
{
if(p[i].CPU_burst < smallest_burst)
{
smallest_burst = p[i].CPU_burst;
smallest_burst_index = i;
}
if(p[i].I/O_Time < smallest_I/O_Time)
{
smallest_I/O_Time = p[i].I/O_Time;
smallest_I/O_Time_index = i;
}
}
cout << endl;
cout<<"Process" << " " << "Burst" << " " << "Arrival" << endl;
for(int i=0; i<numberOfProcesses; i++)
{
cout <<"P" << p[smallest_I/O_Time_index].processId << " " << p[smallest_I/O_Time_index].CPU_burst << " " << p[smallest_I/O_Time_index].I/O_Time << endl;
cout <<"P" << p[smallest_burst_index].processId << " " << p[smallest_burst_index].CPU_burst << " " << p[smallest_burst_index].I/O_Time << end1;
}
return 0;
}