Question: In C + + Programming, I need help in simulating various CPU scheduling algorithms. Here's the scheduling algorithms I need to simulate: First - Come,
In C Programming, I need help in simulating various CPU scheduling algorithms.
Here's the scheduling algorithms I need to simulate:
FirstCome, FirstServe FCFS
Shortest Job First SJF
Shortest Remaining Time SRT
Round Robin RR
The Output for each simulated algorithm needs to display the following for each of the above processes:
o Process ID
o Arrival Time
o Burst Time
o Average Waiting Time The time a process spends in the ready queue before it starts
execution.
o Average Turnaround Time The total time taken for a process to complete from the
time of its arrival.
Output Example
Process Arrival Time Burst Time Waiting Time Turnaround Time
P
P
P
P
Average Waiting Time:
Average Turnaround Time:
Here's what I have so far:
#include
#include
#include
using namespace std;
Process Definitions
struct Process
int pid;
int arrivaltime;
int bursttime;
int waitingtime;
int turnaroundtime;
int remainingtime;
Processint id int at int bt
pid id;
arrivaltime at;
bursttime bt;
waitingtime ;
turnaroundtime ;
remainingtime bt;
;
input data
vector processes
Process
Process
Process
Process
;
Scheduling Algorithms:
FirstCome, FirstServe FCFS
void fcfsschedulingvector& processes
sortprocessesbegin processes.endProcess a Process b
return aarrivaltime barrivaltime;
;
int currenttime ;
for auto& process : processes
if currenttime process.arrivaltime
currenttime process.arrivaltime;
process.waitingtime currenttime process.arrivaltime;
process.turnaroundtime process.waitingtime
process.bursttime;
currenttime process.bursttime;
Shortest Job First SJF
void sjfschedulingvector& processes
Sort processes based on arrival time, then burst time
sortprocessesbegin processes.endProcess& a
Process& b
return aarrivaltime barrivaltime abursttime
bbursttime : aarrivaltime barrivaltime;
;
int currenttime ;
vector readyqueue;
vector completedprocesses;
Add processes to ready queue and select the shortest job
Execute the shortest job and continue the loop
Shortest Remaining Time SRT
void srtschedulingvector& processes
int currenttime ;
vector readyqueue;
Continue to pick processes based on remaining time
Preempt the process when needed and update the
remaining time
Round Robin RR
void roundrobinschedulingvector& processes, int
timequantum
int currenttime ;
vector readyqueue;
Loop through processes, run for the time quantum, and
rotate
Display Output
void displayresultsconst string& algorithmname, const
vector& processes
cout "Results for algorithmname : endl;
Display results
for const auto& process : processes
cout "Process ID: process.pid Arrival Time:
process.arrivaltime Burst Time: process.bursttime Waiting Time:
process.waitingtime
Turnaround Time: process.turnaroundtime
endl;
Calculate and display the average waiting and turnaround
times to be implemented
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
