An implementation of various CPU scheduling algorithms in C++. The algorithms include:
- First Come First Serve (FCFS)
- Round Robin (RR)
- Shortest Process Next (SPN)
- Shortest Remaining Time (SRT)
- Highest Response Ratio Next (HRRN)
- Feedback (FB)
- Feedback with varying time quantum (FBV)
- Aging
Non-preemptive algorithm where the process that arrives first gets executed first. Simple but may cause performance issues if long processes come early.
Preemptive algorithm using time slices (quantum). With varying quantum, it can better balance CPU time across short and long processes.
Non-preemptive algorithm where the process with the shortest burst time is selected next. Reduces average waiting time but can starve longer tasks.
Preemptive version of SPN. A running process can be interrupted if a shorter one arrives. Useful when burst time is unknown in advance.
Non-preemptive. Chooses the process with the highest response ratio, calculated as:
Response Ratio = (Waiting Time + Burst Time) / Burst Time
Favors long-waiting processes, reducing starvation.
Multi-level preemptive algorithm using priority queues. A process can be demoted to a lower-priority queue after execution.
Same as FB, but each queue uses a different time quantum, allowing for more fine-tuned control.
Addresses starvation in priority-based systems by gradually increasing the priority of waiting processes. Ensures that all processes eventually get CPU time.
# Clone the repository
git clone https://github.com/yourusername/CPU-Scheduling-Algorithms.git
cd CPU-Scheduling-Algorithms
# Install compiler tools
sudo apt-get install g++ make
# Build the project
make
# Run the executable
./cpu_scheduling
- Line 1:
"trace"
or"stats"
- Line 2: List of scheduling policies with optional parameters (e.g.,
2-4
for RR with q=4) - Line 3: Integer
T
– last instant of the simulation - Line 4: Number of processes
N
- Next N Lines: Process description
- For Algorithms 1–7:
Name, ArrivalTime, ServiceTime
- For Algorithm 8 (Aging):
Name, ArrivalTime, Priority
👉 Processes are sorted by arrival time. In case of a tie, the one with the lower priority arrives first.
📎 Check the testcases folder for sample inputs.