A comprehensive CPU scheduling algorithm simulator built in C++ with Qt GUI support. This project implements and compares 10 different scheduling policies commonly used in operating systems.
Scheduler Simulator is a powerful tool for analyzing and visualizing CPU scheduling algorithms. It supports both interactive GUI and command-line interfaces, allowing users to:
- Simulate various CPU scheduling policies
- Compare performance across different algorithms
- Visualize Gantt charts and performance metrics
- Run batch experiments and generate reports
- Import custom workloads from JSON files
- FCFS (First Come First Served) - Non-preemptive
- SJF (Shortest Job First) - Non-preemptive
- SRTF (Shortest Remaining Time First) - Preemptive
- RR (Round Robin) - Preemptive with configurable time quantum
- PRIORITY - Priority-based scheduling
- MLFQ (Multi-Level Feedback Queue) - Advanced preemptive scheduling
- LOTTERY - Probabilistic scheduling
- STRIDE - Deterministic proportional-share scheduling
- EDF (Earliest Deadline First) - Real-time scheduling
- RMS (Rate Monotonic Scheduling) - Real-time scheduling
- Multiple Interfaces: GUI with Gantt chart visualization, command-line CLI, and batch processing
- Rich Metrics:
- CPU Utilization
- Throughput
- Average Turnaround Time
- Average Waiting Time
- Per-Process CPU Time
- Jain's Fairness Index
- Deadline Miss Statistics
- Average Lateness
- Burst Simulation: Support for CPU bursts and I/O bursts
- Real-time Support: Deadline and period specifications
- Lottery Scheduling: Ticket-based resource allocation
- STRIDE Scheduling: Stride values for proportional sharing
- JSON Workload Import: Define complex workloads declaratively
- CSV Export: Export results for further analysis
- Experiment Framework: Run comparative studies across multiple algorithms
- C++ Compiler: GCC, Clang, or MSVC supporting C++17 or later
- CMake: Version 3.10 or higher
- Qt5: (Optional, for GUI) Version 5.x with Widgets and Charts modules
- nlohmann/json: JSON library for C++
- Windows, macOS, or Linux
- Minimum 256 MB RAM
- 50 MB disk space
git clone https://github.com/yourusername/scheduler-sim.git
cd scheduler-simWindows (MSVC + vcpkg):
vcpkg install nlohmann-json:x64-windows
vcpkg install qt5:x64-windows # For GUIUbuntu/Debian:
sudo apt-get install build-essential cmake nlohmann-json3-dev
sudo apt-get install qtbase5-dev libqt5charts5-dev # For GUImacOS (Homebrew):
brew install cmake nlohmann-json
brew install qt5 # For GUImkdir build
cd build
cmake ..
cmake --build . --config ReleaseBuild Options:
# Build without GUI (CLI only)
cmake .. -DBUILD_GUI=OFF
cmake --build . --config Release
# Build with GUI (default)
cmake ..
cmake --build . --config Releasecmake --install .Run the GUI version for interactive scheduling simulation:
# Windows
build\Release\scheduler_gui.exe
# Linux/macOS
./build/scheduler_guiFeatures:
- Load process definitions from JSON files
- Select scheduling algorithm and adjust parameters
- View real-time simulation results
- Display Gantt charts for visualization
- Compare algorithms side-by-side
- Run batch experiments
For automated simulations and scripting:
# Basic simulation
./scheduler_cli <json_file> <algorithm> [quantum]
# Example
./scheduler_cli example/sample.json fcfs
./scheduler_cli example/sample.json rr 4
./scheduler_cli example/workload_realtime.json edfArguments:
<json_file>: Path to process definition file<algorithm>: One of: FCFS, SJF, SRTF, RR, PRIORITY, MLFQ, LOTTERY, STRIDE, EDF, RMS[quantum]: Time quantum for Round Robin (default: 2)
Run comparative analysis across multiple algorithms:
./experiment_runner <json_file> [output_dir]
# Example
./experiment_runner example/workload_heavy.json output/experimentsAnalyze and compare simulation outputs:
./compare <output_dir>Define processes and their characteristics using JSON files. See example/ directory for reference implementations.
[
{
"pid": 1, // Process ID (integer or string)
"arrival": 0, // Arrival time
"bursts": [5, 3, 4], // CPU burst times (I/O assumed between)
"priority": 3, // Priority level (lower = higher priority)
"deadline": 50, // Absolute deadline (optional, -1 if none)
"period": 0, // Period for periodic tasks (optional)
"tickets": 10 // Lottery tickets (optional, default 1)
},
{
"pid": 2,
"arrival": 2,
"bursts": [4, 2],
"priority": 1,
"deadline": 40
}
]| Field | Type | Description | Required |
|---|---|---|---|
| pid | int/string | Process identifier | β |
| arrival | int | Time when process enters system | β |
| bursts | array | CPU burst times (I/O bursts inserted between) | β |
| priority | int | Priority level (1 = highest) | β |
| deadline | int | Absolute deadline for real-time tasks | β |
| period | int | Period for periodic tasks | β |
| tickets | int | Number of lottery tickets | β |
- sample.json: Basic general-purpose processes
- workload_basic.json: Simple workload
- workload_heavy.json: Heavy computation workload
- workload_random.json: Randomly generated workload
- workload_realtime.json: Real-time periodic tasks
- workload_multiburst.json: Processes with multiple CPU/I/O bursts
The graphical interface provides an intuitive environment for scheduling simulation:
Main Window Components:
- Process Configuration Panel: Add/edit processes with custom burst sequences
- Algorithm Selection: Dropdown menu to choose scheduling policy
- Parameter Settings: Configure time quantum, priorities, deadlines
- Gantt Chart Visualization: Real-time display of process execution timeline
- Performance Metrics Dashboard: Live metrics display with charts
- Results Table: Detailed per-process statistics
![]() |
![]() |
![]() |
|---|---|---|
![]() |
![]() |
![]() |
Tabs/Windows:
- Simulator Tab: Run single simulations
- Experiments Tab: Run comparative analysis
- Results Tab: View and export metrics
- Charts Tab: Visualize performance graphs
$ ./scheduler_cli example/sample.json RR --quantum 4
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SCHEDULER SIMULATOR - CLI OUTPUT β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Configuration:
Workload File: example/sample.json
Algorithm: Round Robin (RR)
Time Quantum: 4
Processes: 5
Verbose Mode: OFF
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
PROCESS DETAILS:
βββββββ¬βββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββββββ
β PID β Arrivalβ Priority β Deadline β Total Burst β
βββββββΌβββββββββΌβββββββββββΌβββββββββββΌβββββββββββββββ€
β P1 β 0 β 3 β 50 β 5 units β
β P2 β 0 β 2 β 60 β 9 units β
β P3 β 1 β 1 β 40 β 6 units β
β P4 β 2 β 5 β 35 β 4 units β
β P5 β 3 β 4 β 45 β 3 units β
βββββββ΄βββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
SIMULATION TIMELINE:
Time: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
CPU : P1 P1 P1 P1 P2 P2 P2 P2 P3 P3 P3 P3 P4 P4 P5 P5 P1 -- --
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
SIMULATION RESULTS:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Metric β Value β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Makespan (Total Time) β 18 units β
β CPU Utilization β 94.44% β
β Throughput β 0.278 proc/unit β
β Average Turnaround Time β 13.40 units β
β Average Waiting Time β 6.60 units β
β Jain's Fairness Index β 0.89 β
β Deadline Misses β 0 β
β Average Lateness β 0.00 units β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
PER-PROCESS STATISTICS:
ββββββββ¬βββββββββββ¬βββββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββ
β PID β CPU Time β Start Time β Finish β Turnaround β Waiting β
β β Received β β Time β Time β Time β
ββββββββΌβββββββββββΌβββββββββββββΌβββββββββββΌβββββββββββΌβββββββββββ€
β P1 β 5 β 0 β 16 β 16 β 11 β
β P2 β 9 β 4 β 18 β 18 β 5 β
β P3 β 6 β 8 β 14 β 13 β 8 β
β P4 β 4 β 12 β 15 β 13 β 11 β
β P5 β 3 β 14 β 17 β 14 β 14 β
ββββββββ΄βββββββββββ΄βββββββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββ
Simulation completed successfully in 2.34 ms
Output file: output/timeline_RR.csv$ ./experiment_runner example/workload_heavy.json output/experiments
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BATCH EXPERIMENT RUNNER β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Workload: workload_heavy.json
Output Directory: output/experiments
Processes: 8
Total Experiments: 80 (10 algorithms Γ 8 variations)
Running Experiments:
[ββββββββββββββββββββββββββ] 25% - Algorithm: FCFS
[ββββββββββββββββββββββββββ] 50% - Algorithm: RR
[ββββββββββββββββββββββββββ] 75% - Algorithm: EDF
[ββββββββββββββββββββββββββββ] 100% - Algorithm: RMS
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
COMPARATIVE RESULTS:
Algorithm β CPU Util β Throughput β Avg Wait β Avg Turn β Fair
ββββββββββββββΌβββββββββββΌβββββββββββββΌβββββββββββΌβββββββββββΌββββββ
FCFS β 92.31% β 0.154 β 28.5 β 43.2 β 0.65
SJF β 94.87% β 0.159 β 12.8 β 27.5 β 0.72
SRTF β 95.12% β 0.161 β 11.2 β 26.0 β 0.75
RR (q=2) β 91.23% β 0.148 β 18.6 β 33.4 β 0.88
PRIORITY β 93.45% β 0.155 β 21.3 β 36.2 β 0.58
MLFQ β 95.67% β 0.162 β 10.1 β 24.8 β 0.82
LOTTERY β 94.23% β 0.157 β 15.9 β 30.7 β 0.79
STRIDE β 94.89% β 0.160 β 14.2 β 29.1 β 0.81
EDF β 93.78% β 0.156 β 17.4 β 32.1 β 0.70
RMS β 92.56% β 0.152 β 22.8 β 37.5 β 0.68
Most Efficient: MLFQ (95.67% CPU util, 10.1 avg wait)
Best Fairness: RR (0.88 fairness index)
Lowest Latency: MLFQ (10.1 average waiting time)
Output Files Generated:
β output/experiments/results_summary.csv
β output/experiments/timeline_comparison.csv
β output/experiments/algorithm_stats.json
β output/experiments/plots/cpu_utilization.png
β output/experiments/plots/fairness_comparison.png
β output/experiments/plots/latency_comparison.png
Experiment completed in 5.32 seconds$ ./compare output/experiments
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β RESULTS COMPARISON TOOL β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Analyzing: output/experiments/
Found 10 timeline files
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
SUMMARY STATISTICS:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Metric β Best β Worst β Average β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β CPU Utilization β 95.67% β 91.23% β 93.81% β
β Average Wait Time β 10.1 β 28.5 β 17.29 β
β Average Turnaround β 24.8 β 43.2 β 32.08 β
β Throughput β 0.162 β 0.148 β 0.1553 β
β Fairness Index β 0.88 β 0.58 β 0.74 β
β Deadline Misses β 0 β 5 β 1.2 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
RANKING BY METRIC:
By CPU Utilization:
1. MLFQ (95.67%) β Best
2. SRTF (95.12%)
3. SJF (94.87%)
By Average Waiting Time:
1. MLFQ (10.1) β Best (Lowest Latency)
2. SRTF (11.2)
3. SJF (12.8)
By Fairness (Jain's Index):
1. RR (0.88) β Most Fair
2. MLFQ (0.82)
3. STRIDE (0.81)
By Deadline Meeting (Real-time):
1. EDF/RMS (0 misses) β Best for Real-time
2. Others (0-5 misses)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Report generated: output/experiments/comparison_report.html
CSV Export: output/experiments/compare_results.csvβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SCHEDULER SIMULATOR β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β²
βββββββββββββββΌββββββββββββββ
βΌ βΌ βΌ
ββββββββββ ββββββββββββ βββββββββββββ
β GUI β β CLI β β Batch β
β App β β Console β β Processor β
βββββ¬βββββ ββββββ¬ββββββ βββββββ¬ββββββ
β β β
ββββββββββββββΌβββββββββββββββ
βΌ
βββββββββββββββββββ
β Input Manager β
β (JSON Parser) β
ββββββββββ¬βββββββββ
βΌ
ββββββββββββββββββββββββ
β Simulator Engine β
β β
β ββββββββββββββββββ β
β β Policy Router β β
β ββββββββββββββββββ β
β βΌ β
β ββββββββββββββββββ β
β β 10 Algorithm β β
β β Implementations
β ββββββββββββββββββ β
β βΌ β
β ββββββββββββββββββ β
β β Metrics β β
β β Calculator β β
β ββββββββββββββββββ β
ββββββββββ¬ββββββββββββββ
βΌ
ββββββββββββββββββββββββ
β Output Generator β
β (CSV, JSON, Charts) β
ββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER INPUT (GUI, CLI, or Batch File) β
ββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββ
β JSON Workload Parser β
β - Parse processes β
β - Validate data β
β - Initialize burst queues β
ββββββββββββββ¬ββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββ
β Scheduler Selection β
β - Map algorithm name β
β - Set parameters (quantum) β
β - Configure queues β
ββββββββββββββ¬ββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββ
β MAIN SIMULATION LOOP β
β β
β for each time unit: β
β ββ Check arrivals β
β ββ Update burst status β
β ββ Call scheduler algorithm β
β ββ Dispatch selected process β
β ββ Record timeline β
β ββ Update statistics β
β β
β until all processes finished β
ββββββββββββββ¬ββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββ
β Metrics Calculation β
β - CPU Utilization β
β - Turnaround Time β
β - Waiting Time β
β - Fairness Index β
β - Deadline Analysis β
ββββββββββββββ¬ββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββ
β Results Export β
β - CSV Timeline β
β - JSON Metrics β
β - Visual Charts β
ββββββββββββββ¬ββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββ
β Display/Store Results β
β - GUI widgets β
β - Console output β
β - File output β
ββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββ
β Process β
βββββββββββββββββββββββββββββββββββββββββββββββ€
β - pid: int β
β - arrivalTime: int β
β - priority: int β
β - bursts: vector<Burst> β
β - deadline: int β
β - period: int β
β - tickets: int (for lottery) β
β - stride: double (for stride scheduling) β
βββββββββββββββββββββββββββββββββββββββββββββββ
β²
β contains
β
βββββββββββββββββββββββββββββββββββββββββββββββ
β Burst β
βββββββββββββββββββββββββββββββββββββββββββββββ€
β - isCpu: bool β
β - timeNeeded: int β
βββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββ
β Simulator β
ββββββββββββββββββββββββββββββββββββββββββββββββ€
β + run(processes, policy, quantum): Result β
β β
β Private Methods: β
β - runFCFS() β
β - runSJF() β
β - runSRTF() β
β - runRR() β
β - runPriority() β
β - runMLFQ() β
β - runLottery() β
β - runStride() β
β - runEDF() β
β - runRMS() β
β - calculateMetrics() β
ββββββββββββββββββββββββββββββββββββββββββββββββ
βΌ
β returns
β
ββββββββββββββββββββββββββββββββββββββββββββββββ
β SimulatorResult β
ββββββββββββββββββββββββββββββββββββββββββββββββ€
β - cpuUtilization: double β
β - throughput: double β
β - avgTurnaround: double β
β - avgWaiting: double β
β - jainFairness: double β
β - timeline: vector<int> β
β - perProcessCpu: vector<int> β
β - deadlineMisses: int β
β - avgLateness: double β
β - makespan: int β
ββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββ
β Qt Main Window β
ββββββββββ¬βββββββββ
β
ββββββ΄βββββββββ¬βββββββββββββββ¬βββββββββββββββ
βΌ βΌ βΌ βΌ
ββββββββββ ββββββββββββ ββββββββββββββ ββββββββββββββββ
βProcess β βAlgorithm β βGantt β βResults β
βTable β βSelector β βWidget β βTable β
βWidget β βWidget β β β βWidget β
ββββββ¬ββββ ββββββ¬ββββββ ββββββββββββββ ββββββββββββββββ
β β
βββββββββββββΌβββββββββββββββββββ
βΌ βΌ
ββββββββββββββββββββ ββββββββββββββββ
βSimulatorWidget β βExperiments β
β(Core Logic) β βWidget β
ββββββββββ¬ββββββββββ ββββββββββββββββ
β
βΌ
ββββββββββββββββββββ
βSimulator Engine β
β(C++) β
ββββββββββ¬ββββββββββ
β
βΌ
ββββββββββββββββββββ
βResults Object β
β(C++) β
ββββββββββ¬ββββββββββ
β
ββββββββββββΌβββββββββββ
βΌ βΌ βΌ
ββββββββββ ββββββββββββ ββββββββββββ
βGantt β βResults β βChart β
βRender β βDisplay β βDisplay β
βEngine β βEngine β βEngine β
ββββββββββ ββββββββββββ ββββββββββββ
βββββββββββββββββββββββ
β Start Simulation β
ββββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββ
βWhich Policy? β
ββββββββ¬ββββββββ
β
ββββββββ΄βββββββββββββββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββ ββββββββββββββββββββ
βNon- β βReal-Time β
βPreemptive β βScheduling β
ββββ¬βββ¬βββ¬βββββ ββββ¬ββββββββ¬βββββββββ
β β β β β
FCFS SJF PRIO EDF RMS
β β β β β
ββββ΄βββ΄ββββββββ βββββ¬ββββ
β β
βΌ βΌ
ββββββββββββββββββ ββββββββββββββββββββ
βPreemptive β βCheck Deadlines β
ββ¬ββββ¬ββ¬ββββ¬ββββββ βRecord Misses β
β β β β βCalculate Lateness
SRTF RR MLFQ β ββββββββββββββββββββ
β
βββββββ΄βββββββ
β β
LOTTERY STRIDE
β β
βββββββ¬ββββββββ
β
βΌ
ββββββββββββββββββββββ
βExecute Process β
βUpdate Timelines β
βTrack Metrics β
ββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββ
βAll Processes β
βFinished? β
βββββ¬βββββββββββ¬βββββββ
β No β Yes
β β
βΌ βΌ
Continue Calculate
Final Metrics
Performance Metrics:
- CPU Utilization %: Percentage of time CPU is actively processing
- Throughput: Number of processes completed per unit time
- Average Turnaround Time: Mean time from arrival to completion
- Average Waiting Time: Mean time spent waiting in queue
Fairness & Real-time Metrics:
- Jain's Fairness Index: Measure of fair CPU distribution (0-1, higher is fairer)
- Per-Process CPU Time: Actual CPU time received by each process
- Deadline Misses: Count of processes that missed deadlines
- Average Lateness: Mean finish time - deadline for late processes
All output files are generated in the output/ directory:
timeline_<ALGORITHM>.csv: Gantt chart timelinecompare_results.csv: Comparative metrics across algorithmsplots/: Generated visualization files
Simulation Results
==================
Algorithm: Round Robin (quantum=4)
Makespan: 45
CPU Utilization: 93.33%
Throughput: 0.089 processes/time-unit
Average Turnaround Time: 31.67
Average Waiting Time: 18.33
Jain's Fairness Index: 0.92
Deadline Misses: 1
Average Lateness: 5.0
Timeline:
Time: 0 1 2 3 4 5 6 7 8 9 ...
CPU : P1 P1 P2 P2 P3 P3 P1 P2 P1 - ...
scheduler-sim/
βββ src/ # Source files
β βββ main_gui.cpp # Qt GUI application
β βββ main_console.cpp # CLI interface
β βββ experiment_runner.cpp # Batch experiment runner
β βββ compare.cpp # Results comparison tool
β βββ Simulator.cpp # Core simulation engine
β βββ Process.cpp # Process definition
β βββ Burst.cpp # Burst definition
β βββ ExponentialAveraging.cpp # Prediction algorithm
β βββ gui/ # Qt GUI components
β βββ GanttWidget.cpp # Gantt chart visualization
β βββ ResultsChartWidget.cpp
β βββ ResultsTableWidget.cpp
β βββ SimulatorWidget.cpp
β βββ ExperimentsWidget.cpp
βββ include/ # Header files
β βββ Simulator.hpp
β βββ Process.hpp
β βββ Burst.hpp
β βββ ExponentialAveraging.hpp
β βββ ResultsChartWidget.hpp
β βββ json.hpp
βββ example/ # Example workload files
β βββ sample.json
β βββ workload_basic.json
β βββ workload_heavy.json
β βββ workload_random.json
β βββ workload_realtime.json
βββ output/ # Generated results
β βββ timeline_*.csv
β βββ compare_results.csv
β βββ plots/
βββ build/ # Build directory
βββ CMakeLists.txt # Build configuration
βββ analyze_results.py # Python analysis scripts
βββ README.md # This file
Simulator.hpp/cpp: Main simulation engine
- Implements 10 scheduling algorithms
- Maintains process queues and state
- Calculates performance metrics
- Generates Gantt chart timelines
Process.hpp/cpp: Process representation
- Stores process attributes
- Tracks CPU/IO bursts
- Manages scheduling-specific data
Burst.hpp/cpp: CPU/IO burst definition
- Represents work units
- Supports mixed CPU and I/O workloads
ExponentialAveraging.hpp/cpp: Prediction algorithm
- Used by MLFQ for burst prediction
- Smooths historical data
Overview:
- Simplest scheduling algorithm
- Processes execute in arrival order
- No preemption once started
Characteristics:
Advantages:
β Minimal overhead
β Fair (in FIFO order)
β Easy to implement
Disadvantages:
β Convoy effect (short jobs wait for long jobs)
β Poor average waiting time
β Not suitable for time-sharing
β Ignores process priority
Timeline Example:
P1 (5) β P2 (3) β P3 (4)
[P1|P1|P1|P1|P1|P2|P2|P2|P3|P3|P3|P3]
0 1 2 3 4 5 6 7 8 9 10 11
Turnaround: P1=5, P2=8, P3=12 (Avg=8.33)
Waiting: P1=0, P2=5, P3=8 (Avg=4.33)
Best For: Batch processing, offline jobs
Worst For: Interactive systems, time-sharing
Overview:
- Execute process with shortest total burst time first
- Non-preemptive optimal algorithm for average waiting time
- Requires knowledge or prediction of CPU time
Characteristics:
Advantages:
β Provably minimizes average waiting time
β Good for batch processing
β Reduces starvation risk vs arrival order
Disadvantages:
β Requires CPU time prediction/knowledge
β Long processes may starve
β Cannot be implemented without foreknowledge
β Not practical for interactive systems
Timeline Example:
P1 (5) β P2 (3) β P3 (4)
Sorted: P2 (3) β P3 (4) β P1 (5)
[P2|P2|P2|P3|P3|P3|P3|P1|P1|P1|P1|P1]
0 1 2 3 4 5 6 7 8 9 10 11
Turnaround: P2=3, P3=7, P1=12 (Avg=7.33)
Waiting: P2=0, P3=3, P1=7 (Avg=3.33)
Best For: Batch systems, known job lengths
Worst For: Interactive systems, unknown burst times
Overview:
- Processes ranked by priority level
- Highest priority ready process executes
- No preemption during execution
Characteristics:
Priority Levels (implementation dependent):
- Priority 1: Highest
- Priority 5: Lowest
- Some systems use 0-100 scale
Advantages:
β Flexible prioritization
β Good for mixed workloads
β Can ensure critical processes run first
Disadvantages:
β Can cause starvation of low-priority processes
β Requires proper priority assignment
β Priority inversion issues possible
Best For: Systems with mixed criticality, embedded systems
Overview:
- Preemptive version of SJF
- Always executes process with shortest remaining burst
- Requires preemption capability
Characteristics:
Advantages:
β Optimal for minimizing average waiting time
β Good responsiveness
β Better than SJF
Disadvantages:
β Context switch overhead
β Requires CPU time prediction
β Complex implementation
β Long processes heavily penalized (starvation risk)
Timeline Example:
P1 (5) β P2 (3) arrives at t=1 β P3 (4) arrives at t=2
Time: 0 1 2 3 4 5 6 7 8 9 10 11 12 13
CPU: [P1|P2|P2|P2|P3|P3|P3|P3|P1|P1|P1|P1|P1]
(P2 preempts at t=1 with 3 remaining)
(P3 preempts at t=2 with 4 remaining)
Best For: General-purpose time-sharing, low latency required
Overview:
- Each process gets fixed time quantum (typically 10-100ms)
- Cyclic queue: processes rotate after using quantum
- Preemptive within quantum boundaries
Characteristics:
Time Quantum Selection:
- Too small: High context switch overhead
- Too large: Approaches FCFS behavior
- Typical: 10-100 ms in real systems
- For simulation: 2-4 units common
Advantages:
β Fair distribution of CPU time
β Good responsiveness for interactive users
β No starvation
β Predictable maximum wait time
Disadvantages:
β Context switch overhead
β Quantum selection critical for performance
β Not optimal for any metric
Timeline Example (Quantum = 4):
P1 (5) β P2 (4) β P3 (6)
Initial Queue: [P1, P2, P3]
Time: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
CPU: [P1|P1|P1|P1|P2|P2|P2|P2|P3|P3|P3|P3|P1|P3]
Quantum usage:
P1: Gets 4 (finishes at 13 with 1 remaining)
P2: Gets 4 (finishes at 8)
P3: Gets 4 (gets 2 more later, finishes at 14)
Best For: Time-sharing, interactive systems
Configuration: Quantum = [2-4]
Overview:
- Multiple priority queues (typically 3-4 levels)
- Processes move between queues based on behavior
- I/O-bound processes rise; CPU-bound processes sink
- Adapts scheduling to workload type
Queue Structure:
Priority 0 (Highest) β [I/O-bound processes] β Quantum: 8ms
Priority 1 (Medium) β [Mixed processes] β Quantum: 16ms
Priority 2 (Lowest) β [CPU-bound processes] β Quantum: 32ms
Feedback Mechanisms:
- Process uses full quantum β demote to lower queue
- Process yields early (I/O) β promote to higher queue
- Periodic boost of all processes to prevent starvation
Characteristics:
Advantages:
β Adapts to process behavior automatically
β Good interactivity and throughput balance
β Prevents starvation with periodic reset
β Excellent average performance
Disadvantages:
β Complex implementation
β Many tunable parameters
β Unpredictable behavior in real-time scenarios
Best For: General-purpose time-sharing (Unix-like systems)
Overview:
- Preemptive version of priority scheduling
- Higher priority process preempts lower priority
- Can use dynamic or static priorities
Characteristics:
Advantages:
β Good responsiveness to high-priority events
β Can ensure critical processes complete first
Disadvantages:
β Risk of starvation for low-priority processes
β Requires careful priority assignment
β Possible priority inversion issues
Best For: Real-time systems, interrupt handlers
Overview:
- Ticket-based probabilistic approach
- Each process receives lottery tickets
- CPU time proportional to ticket count
- Selected randomly at each scheduling point
Mechanism:
Tickets Distribution:
P1: 10 tickets β expects 10/(10+20+30) = 16.7% CPU
P2: 20 tickets β expects 20/60 = 33.3% CPU
P3: 30 tickets β expects 30/60 = 50% CPU
Selection:
Random number 0-59:
0-9: Select P1
10-29: Select P2
30-59: Select P3
Characteristics:
Advantages:
β Proportional allocation
β No starvation (each ticket guarantees some CPU)
β Simple concept
β Prevents priority inversion
Disadvantages:
β Non-deterministic (randomness)
β Variance in actual CPU share
β Not suitable for real-time
β Requires ticket management overhead
Best For: Fair scheduling, proportional resource allocation
Fairness Guarantee: Jain's Index β 0.9+
Overview:
- Deterministic alternative to Lottery
- Each process has stride value: stride = 1000000/tickets
- Process with smallest pass value executes next
- Pass value incremented by stride after execution
Mechanism:
Tickets: P1=10, P2=20, P3=30
Strides: P1=100000, P2=50000, P3=33333
Pass Values (initially 0):
Round 1: Min(0,0,0) = P1 runs β P1.pass = 100000
Round 2: Min(100000,0,0) = P2 runs β P2.pass = 50000
Round 3: Min(100000,50000,0) = P3 runs β P3.pass = 33333
Round 4: Min(100000,50000,33333) = P3 runs β P3.pass = 66666
Round 5: Min(100000,50000,66666) = P2 runs β P2.pass = 100000
Round 6: Min(100000,100000,66666) = P3 runs β P3.pass = 100000
...
Characteristics:
Advantages:
β Deterministic (reproducible)
β Proportional allocation
β No starvation
β Better fairness than Lottery
β Low variance in CPU share
Disadvantages:
β More complex than Lottery
β Still not for hard real-time
β Stride calculation needed
Best For: Fair bandwidth allocation, server environments
Fairness Guarantee: Deterministic proportional share
Overview:
- Always execute process with earliest deadline
- Optimal for meeting deadlines in uniprocessor
- Preemptive, dynamic priority
Algorithm:
At each scheduling point:
1. Among ready processes, select one with earliest deadline
2. If new process arrives with earlier deadline, preempt current
3. Track deadline misses and lateness
Deadline Miss Tracking:
- If finish_time > deadline β miss
- Lateness = finish_time - deadline
Characteristics:
Advantages:
β Optimal for uniprocessor scheduling
β Handles mixed deadlines
β Good utilization
β Tracks real-time metrics
Disadvantages:
β Not suitable for non-deadline tasks
β No priority among tasks with same deadline
β Requires deadline specification
Feasibility Test (Liu-Layland):
Utilization = Ξ£(CPU_time / Period)
If Utilization β€ 1.0 β EDF is feasible
Best For: Hard real-time systems, deadline-driven tasks
Example:
P1: deadline=10, CPU=3
P2: deadline=8, CPU=2
P3: deadline=15, CPU=4
Scheduling:
Execute P2 (earliest deadline 8) first
Then P1 (deadline 10)
Then P3 (deadline 15)
Overview:
- Static priority based on period
- Process with shortest period gets highest priority
- Period = 1/frequency = priority
- Optimal for periodic, preemptive real-time tasks
Priority Assignment:
Example with periods:
P1: period=4ms β Priority 1 (Highest)
P2: period=5ms β Priority 2
P3: period=7ms β Priority 3 (Lowest)
Shorter period = Higher priority = Executes first
Characteristics:
Advantages:
β Optimal static priority assignment
β Proven by Liu-Layland theorem
β Simple priority calculation
β Deterministic scheduling
Disadvantages:
β Only for periodic tasks
β Not optimal for aperiodic tasks
β Fixed priorities (less flexible than EDF)
β Period must be known
Feasibility Test (Liu-Layland):
For n periodic tasks:
Utilization = Ξ£(CPU_time_i / Period_i)
If Utilization β€ n(2^(1/n) - 1):
RMS is GUARANTEED to meet all deadlines
For large n, threshold β 0.693
For n=1, threshold = 1.0
For n=2, threshold β 0.828
If Utilization > threshold:
May still be feasible, but not guaranteed by RMS
Example Schedule:
P1: period=4, CPU=1 β Utilization = 1/4 = 0.25
P2: period=5, CPU=2 β Utilization = 2/5 = 0.40
P3: period=7, CPU=2 β Utilization = 2/7 = 0.286
Total Utilization = 0.936
Feasibility check (n=3):
3(2^(1/3) - 1) β 0.78
0.936 > 0.78 β Not guaranteed, but may work
Timeline:
0-1: P1 (P1 period: 4)
1-2: P1 (new P1 arrives)
2-3: P2
3-4: P1 (new)
4-5: P2
5-6: P1
...
Best For: Hard real-time embedded systems
The simulator models scheduling decisions accurately but abstracts context switch time overhead for clarity. In real systems, context switching costs include:
Typical Context Switch Times:
- Modern Linux: 0.1-1 microsecond
- Real-time systems: 1-10 microseconds
- Embedded systems: 10-100 microseconds
Components:
1. Save process state (registers, memory maps)
2. Load new process state
3. TLB/cache flush (expensive!)
4. Jump to new instruction pointer
Problem: Low-priority processes never execute if higher-priority work keeps arriving
Solutions Implemented:
- MLFQ Aging: Periodically boost all processes to highest queue
- RMS Feasibility: Ensures all tasks meet deadlines
- Lottery/Stride: Guarantee minimum CPU share to all processes
- RR Queue: No process waits indefinitely
Deadline Tracking:
For each process:
- If finish_time β€ deadline β On time β
- If finish_time > deadline β Missed β
Metrics:
- Deadline Misses: Count of missed deadlines
- Lateness: Max(0, finish_time - deadline)
- Average Lateness: Mean across all processes
Feasibility Analysis:
Utilization Test:
U = Ξ£(WCET_i / Period_i)
If U β€ threshold:
Schedule is feasible β All deadlines met
Else:
May still be feasible, need detailed analysis
The simulator calculates Jain's Fairness Index to measure fair CPU allocation:
Where
Interpretation:
F = 1.0: Perfect fairness (all processes get equal CPU)
F > 0.9: Very fair
F = 0.8: Fair
F = 0.5: Unfair (some processes starved)
F β 0: Highly unfair (most CPU to single process)
Examples:
[25%, 25%, 25%, 25%] β F = 1.0 (perfect)
[40%, 30%, 20%, 10%] β F = 0.82 (fair)
[100%, 0%, 0%, 0%] β F = 0.25 (very unfair)
Since we don't have actual job execution times, the simulator uses:
Method 1: Known Burst Times
- Use burst array directly (sum for total)
- Simulates oracle knowledge
Method 2: Exponential Averaging (MLFQ)
predicted_n = Ξ± * actual_(n-1) + (1-Ξ±) * predicted_(n-1)
Where Ξ± typically = 0.5 (recent history weight)
Example:
Burst 1: 8ms (predicted = 8)
Burst 2: actual 6ms β predicted = 0.5*6 + 0.5*8 = 7ms
Burst 3: actual 4ms β predicted = 0.5*4 + 0.5*7 = 5.5ms
Algorithm β Throughput β Latency β Fair β Use Case
ββββββββββββββΌβββββββββββββΌββββββββββΌβββββββΌβββββββββββββββββ
FCFS β High β Very Highβ Low β Batch jobs
SJF β Very High β Low β Low β Offline only
SRTF β Very High β Low β Med β General purpose
RR β High β Medium β High β Time-sharing
MLFQ β Very High β Low β High β Most systems
EDF β High β Low β Med β Real-time
RMS β High β Low β Low β Periodic RT
-
Load simple workload:
./scheduler_cli example/sample.json FCFS ./scheduler_cli example/sample.json RR --quantum 4
-
Observe results:
- Compare Gantt charts
- Note differences in metrics
- Understand why FCFS has high waiting times
-
Interactive exploration (GUI):
- Load sample.json
- Try each algorithm
- Watch visualization
-
Run experiments:
./experiment_runner example/workload_heavy.json output/study1 ./compare output/study1
-
Analyze results:
- Which algorithm minimizes wait time?
- Which is most fair?
- What's the throughput ranking?
-
Modify workloads:
- Create custom JSON files
- Vary process count, burst sizes
- Observe algorithm sensitivity
-
Real-time scheduling:
./scheduler_cli example/workload_realtime.json EDF ./scheduler_cli example/workload_realtime.json RMS
-
Analyze feasibility:
- Calculate utilization
- Predict deadline misses
- Test near-capacity scenarios
-
Fair resource allocation:
./scheduler_cli example/workload_random.json LOTTERY --tickets ./scheduler_cli example/workload_random.json STRIDE --tickets
-
Performance optimization:
- Create adversarial workloads
- Test algorithm limits
- Generate comparison reports
Goal: Minimize user-perceptible latency
Recommendation: RR or MLFQ
./scheduler_gui # Use RR with quantum=10 or MLFQWhy:
- Both provide good fairness
- Response time is acceptable
- No process starves
Goal: Maximize throughput
Recommendation: SJF (if burst times known)
./scheduler_cli workloads/batch_jobs.json SJFWhy:
- SJF minimizes average waiting time
- Reduces idle time
- Good for batch queues
Goal: Meet all deadlines, ensure critical tasks first
Recommendation: RMS for periodic, EDF for mixed
./scheduler_cli workloads/rt_tasks.json RMS
./scheduler_cli workloads/rt_tasks.json EDFWhy:
- RMS: Optimal for periodic tasks
- EDF: Optimal for mixed deadlines
- Both guarantee deadline feasibility with proper configuration
Goal: Fair resource allocation among clients
Recommendation: STRIDE or LOTTERY
./scheduler_cli workloads/clients.json STRIDE
./scheduler_cli workloads/clients.json LOTTERYWhy:
- Proportional CPU share
- No starvation
- Deterministic fairness (STRIDE) or statistical fairness (LOTTERY)
Interpretation:
- Idle CPU time = low utilization
- Goal: Maximize (typically 80-95% good)
- 100% = always busy, no gaps
Factors:
- I/O bursts create idle time
- Very short processes increase overhead
- Number of processes affects utilization
What it measures: Total time in system (queue + execution)
Optimization: Minimize for interactive users
What it measures: Time wasted waiting in queue
Goal: Minimize, especially for interactive systems
Relationship: Lower waiting time β better response
What it measures: Time until process first gets CPU
Critical for: Interactive systems (shell, GUI)
Goal: Minimize variance and maximum
Measures: How equally CPU time is distributed
Range: 0 to 1
- 1.0 = perfect fairness
- 0.0 = complete unfairness
Use: Compare algorithmic fairness properties
// workloads/experiment_light.json
[
{"pid": 1, "arrival": 0, "bursts": [2], "priority": 1},
{"pid": 2, "arrival": 1, "bursts": [3], "priority": 2},
{"pid": 3, "arrival": 2, "bursts": [2], "priority": 3}
]# Run experiment
./experiment_runner workloads/experiment_light.json results/light
./compare results/lightLight Workload:
- Few processes (3-5)
- Short bursts (1-5 units)
- Even spacing or clustering
- Use: Algorithm validation
Medium Workload:
- Moderate processes (8-15)
- Medium bursts (5-15 units)
- Variable arrival patterns
- Use: Performance comparison
Heavy Workload:
- Many processes (20+)
- Long bursts (20-100 units)
- Bursty or random arrivals
- Use: Stress testing
Real-time Workload:
- Periodic processes
- Deadlines specified
- Varying periods and deadlines
- Use: Feasibility analysis
{
"pid": "string or int", // Required: Unique identifier
"arrival": "int", // Required: Arrival time (β₯ 0)
"bursts": "[int, ...]", // Required: CPU burst times
"priority": "int (1-highest)", // Optional: Priority level
"deadline": "int", // Optional: Absolute deadline
"period": "int", // Optional: Period for RMS
"tickets": "int (default 1)" // Optional: Lottery tickets
}timeline_ALGORITHM.csv:
time,pid,action,remaining_burst
0,1,START,5
0,1,RUN,-
1,2,ARRIVE,-
1,1,RUN,-
2,1,FINISH,-
2,2,START,4
compare_results.csv:
algorithm,cpu_util,throughput,avg_turnaround,avg_waiting,fairness,deadline_misses
FCFS,92.31,0.154,43.2,28.5,0.65,0
SJF,94.87,0.159,27.5,12.8,0.72,0
...
Simulation Speed:
Slower performance:
- GUI rendering with large process counts (50+)
- CSV export with very long timelines
- MLFQ with multiple queue levels
Faster performance:
- Use CLI instead of GUI for batch processing
- Reduce process count for testing
- Use simpler algorithms (FCFS, RR)
Accurate Benchmarking:
1. Run experiments on idle system
2. Disable GUI for speed benchmarks
3. Use consistent workload sizes
4. Average results over multiple runs
5. Account for system startup overhead
Memory Efficiency:
For 1000+ processes:
- Use CLI (lower memory than GUI)
- Stream results instead of storing all
- Clear old simulation data
- Monitor memory usage during experiments
-
Scheduling Algorithms Foundation
- Liu & Layland (1973): "Scheduling Algorithms for Multiprogramming in a Hard-Real-Time Environment"
- Real-time scheduling theory
-
Proportional-Share Scheduling
- Waldspurger & Weihl (1994): "Lottery Scheduling: Flexible Proportional-Share Resource Allocation"
- Waldspurger & Weihl (1995): "Stride Scheduling: Deterministic Proportional-Share Resource Management"
-
Multi-Level Queue Scheduling
- Silberschatz et al.: "Operating System Concepts"
- Chapter on Process Scheduling
- POSIX Scheduling: https://pubs.opengroup.org/onlinepubs/9699919799/
- Linux Scheduler: https://www.kernel.org/doc/html/latest/scheduler/
- Real-Time Systems: https://www.seas.upenn.edu/~lee/docs/
- "Operating Systems: Three Easy Pieces" - Remzi H. Arpaci-Dusseau
- "Real-Time Systems" - Jane W.S. Liu
- "Operating System Concepts" - Silberschatz, Galvin, Gagne
FCFS:
- β Processes execute in arrival order
- β No preemption occurs
- β Timeline matches sequence
SJF:
- β Shortest processes execute first
- β Minimizes average waiting time
- β All processes eventually complete
RR:
- β Each process gets equal time quantum
- β Processes circulate fairly
- β No starvation
MLFQ:
- β I/O-bound processes in higher queues
- β Periodic boost prevents starvation
- β Demote CPU-bound to lower queues
EDF/RMS:
- β Earliest/highest-priority deadline executes
- β Deadline misses tracked
- β Lateness calculated correctly
- Single-Core Simulation: Multi-processor scheduling not modeled
- Uniform Burst Times: No I/O think time between bursts
- Static Workload: No dynamic process creation/termination
- No Memory/IO: Only CPU scheduling modeled
- Deterministic Simulation: No random variations in burst times
- No Migration: Processes don't migrate between queues dynamically
- Multi-core/multi-processor scheduling
- Dynamic workload generation
- Machine learning for parameter tuning
- 3D Gantt chart visualization
- Real-time performance tracing
- Comparative analysis with actual Linux kernel
- Custom algorithm implementation interface
- Hardware simulation (caches, memory)
- Energy-aware scheduling
- Load balancing simulation
Error: "Could not find Qt5"
# Windows - specify Qt path
cmake .. -DCMAKE_PREFIX_PATH="C:\Qt\5.15.0\msvc2019_64"
# Linux - install Qt5
sudo apt-get install qtbase5-dev libqt5charts5-dev
# macOS
brew install qt5
cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix qt5)Error: "nlohmann_json not found"
# Windows with vcpkg
vcpkg install nlohmann-json:x64-windows
cmake .. -DCMAKE_TOOLCHAIN_FILE=path/to/vcpkg.cmake
# Linux
sudo apt-get install nlohmann-json3-dev
# macOS
brew install nlohmann-jsonCMake configure fails:
# Clean build
rm -rf build/
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)"JSON parsing failed"
Checklist:
β File exists and readable
β Valid JSON syntax (use jsonlint.com)
β All required fields present (pid, arrival, bursts)
β No trailing commas
β Proper array format []
"Algorithm not found"
# Valid algorithms (case-insensitive):
FCFS, SJF, SRTF, RR, PRIORITY, MLFQ, LOTTERY, STRIDE, EDF, RMS
# Example (all valid):
./scheduler_cli file.json fcfs
./scheduler_cli file.json FCFS
./scheduler_cli file.json FcFs"No output generated"
Checklist:
β Check output/ directory exists
β Verify write permissions
β Ensure processes in workload file
β Check console for error messages
β Try with example/sample.json first
Slow performance on GUI
# Use CLI instead for large workloads
./scheduler_cli workloads/huge.json rr
# Or disable GUI build
cmake .. -DBUILD_GUI=OFFSegmentation fault (crash)
# Debug with verbose output
./scheduler_cli workloads/test.json fcfs --verbose
# Try with simpler workload
./scheduler_cli example/sample.json fcfs
# Check workload for invalid valuesgit clone <repo>
cd scheduler-sim
mkdir build && cd build
cmake ..
cmake --build . --config Release# GUI
./scheduler_gui
# CLI
./scheduler_cli ../example/sample.json rr --quantum 4./experiment_runner ../example/workload_heavy.json results
./compare results# CSV file
cat output/timeline_RR.csv
# HTML comparison
open results/comparison_report.htmlThis project is provided as educational and research software. See LICENSE file for complete details.
Free to use for:
- Educational purposes
- Research and academic study
- Personal projects
- Non-commercial use
Restrictions:
- Cannot be sold or relicensed
- Must retain copyright notice
- No warranty provided
If using this simulator in academic work:
@software{scheduler_sim_2026,
title={Scheduler Simulator: CPU Scheduling Algorithm Analysis Tool},
author={Khilesh Chaudhari},
year={2026},
url={https://github.com/Khilesh-01/scheduler-sim}
}This Scheduler Simulator provides a comprehensive platform for understanding, analyzing, and comparing CPU scheduling algorithms. Whether you're a student learning OS concepts, a researcher studying scheduler behavior, or a professional optimizing system performance, this tool offers the insights and flexibility you need.
- Understand algorithms: Visualize how different schedulers behave
- Compare performance: Run experiments across algorithms
- Optimize systems: Identify best scheduler for your workload
- Learn OS concepts: Hands-on exploration of scheduling theory
- Research foundation: Extensible platform for new algorithms
- Start with examples in
example/directory - Create your own workloads
- Run comparative studies
- Contribute improvements
- Share results with community
Thank you for using Scheduler Simulator!
For questions, feedback, or contributions, visit the GitHub repository.
Happy scheduling! π
Project Information:
- Repository: https://github.com/Khilesh-01/scheduler-sim
- Version: 1.0
- Last Updated: January 2026
- Maintained by: Development Community
- Status: Actively Maintained β
- SRTF: Stallings, W. "Operating Systems: Internals and Design Principles"
- MLFQ: Silberschatz, A., Galvin, P. B., & Gagne, G. "Operating System Concepts"
- Lottery Scheduling: Waldspurger, C. A., & Weihl, W. E. (1994)
- STRIDE: Waldspurger, C. A., & Weihl, W. E. (1995)
- EDF: Liu, C. L., & Layland, J. W. (1973)
- RMS: Liu, C. L., & Layland, J. W. (1973)





