CPU Scheduling Simulator
đĄ Overview
This turns the theory from your OS notes into working code â you'll actually SEE why SJF has lower average waiting time than FCFS, instead of just memorizing it for an exam.
â Features to Build
0/4 doneđ§ Step-by-Step Guide
Represent each process as a struct: { int pid, arrivalTime, burstTime, waitingTime; }
For FCFS: sort processes by arrival time, then calculate each one's waiting time as the sum of burst times before it.
For SJF: sort the (already arrived) processes by burst time instead, then calculate waiting times the same way.
Sum up all waiting times and divide by the number of processes to get the average.
Print a small table comparing FCFS vs SJF average waiting time for the same input.
đ Starter Code
struct Process {
int pid, arrivalTime, burstTime, waitingTime;
};
// After sorting by chosen criteria:
int waitTime = 0;
for (int i = 0; i < n; i++) {
processes[i].waitingTime = waitTime;
waitTime += processes[i].burstTime;
}đĄ Pro Tip
Build FCFS completely first and get it 100% correct before adding SJF â reusing a working structure for the second algorithm is much easier than building both at once.