Skip to content

Khilesh-01/scheduler-sim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Scheduler Simulator

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.

πŸ“‹ Overview

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

🎯 Features

Supported Scheduling Algorithms

  1. FCFS (First Come First Served) - Non-preemptive
  2. SJF (Shortest Job First) - Non-preemptive
  3. SRTF (Shortest Remaining Time First) - Preemptive
  4. RR (Round Robin) - Preemptive with configurable time quantum
  5. PRIORITY - Priority-based scheduling
  6. MLFQ (Multi-Level Feedback Queue) - Advanced preemptive scheduling
  7. LOTTERY - Probabilistic scheduling
  8. STRIDE - Deterministic proportional-share scheduling
  9. EDF (Earliest Deadline First) - Real-time scheduling
  10. RMS (Rate Monotonic Scheduling) - Real-time scheduling

Key Capabilities

  • 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

πŸ“¦ Requirements

Build Requirements

  • 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++

System Requirements

  • Windows, macOS, or Linux
  • Minimum 256 MB RAM
  • 50 MB disk space

πŸ”§ Installation & Setup

1. Clone the Repository

git clone https://github.com/yourusername/scheduler-sim.git
cd scheduler-sim

2. Install Dependencies

Windows (MSVC + vcpkg):

vcpkg install nlohmann-json:x64-windows
vcpkg install qt5:x64-windows  # For GUI

Ubuntu/Debian:

sudo apt-get install build-essential cmake nlohmann-json3-dev
sudo apt-get install qtbase5-dev libqt5charts5-dev  # For GUI

macOS (Homebrew):

brew install cmake nlohmann-json
brew install qt5  # For GUI

3. Build the Project

mkdir build
cd build
cmake ..
cmake --build . --config Release

Build Options:

# Build without GUI (CLI only)
cmake .. -DBUILD_GUI=OFF
cmake --build . --config Release

# Build with GUI (default)
cmake ..
cmake --build . --config Release

4. Installation (Optional)

cmake --install .

πŸš€ Usage

GUI Application

Run the GUI version for interactive scheduling simulation:

# Windows
build\Release\scheduler_gui.exe

# Linux/macOS
./build/scheduler_gui

Features:

  • 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

Command-Line Interface

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 edf

Arguments:

  • <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)

Batch Experiments

Run comparative analysis across multiple algorithms:

./experiment_runner <json_file> [output_dir]

# Example
./experiment_runner example/workload_heavy.json output/experiments

Compare Results

Analyze and compare simulation outputs:

./compare <output_dir>

πŸ“ Workload Format (JSON)

Define processes and their characteristics using JSON files. See example/ directory for reference implementations.

Basic Structure

[
    {
        "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 Descriptions

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 βœ—

Example Workloads

  • 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

�️ Screenshots & Output Examples

GUI Interface

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
Image 1 Image 2 Image 3
Image 4 Image 5 Image 6

Tabs/Windows:

  • Simulator Tab: Run single simulations
  • Experiments Tab: Run comparative analysis
  • Results Tab: View and export metrics
  • Charts Tab: Visualize performance graphs

Console/CLI Output Examples

Basic Simulation Output

$ ./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

Batch Experiment Output

$ ./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 Tool Output

$ ./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

πŸ—οΈ System Architecture

High-Level Architecture Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    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) β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Component Interaction Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 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                      β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core Classes Structure

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 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                             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow for GUI Application

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 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    β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Algorithm Decision Tree

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 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

πŸ“Š Output & Results

Metrics Calculated

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

Output Files

All output files are generated in the output/ directory:

  • timeline_<ALGORITHM>.csv: Gantt chart timeline
  • compare_results.csv: Comparative metrics across algorithms
  • plots/: Generated visualization files

Example Output

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 - ...

πŸ—οΈ Project Architecture

Directory Structure

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

Core Components

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

πŸ’‘ Detailed Algorithm Analysis

Non-Preemptive Algorithms

FCFS (First Come First Served)

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


SJF (Shortest Job First)

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


PRIORITY (Non-Preemptive)

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


Preemptive Algorithms

SRTF (Shortest Remaining Time First)

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


RR (Round Robin)

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]


MLFQ (Multi-Level Feedback Queue)

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)


PRIORITY (Preemptive)

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


Proportional Share Scheduling

LOTTERY Scheduling

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+


STRIDE Scheduling

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


Real-Time Scheduling

EDF (Earliest Deadline First)

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)

RMS (Rate Monotonic Scheduling)

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


οΏ½ Advanced Topics

Context Switching & Overhead

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

Handling Process Starvation

Problem: Low-priority processes never execute if higher-priority work keeps arriving

Solutions Implemented:

  1. MLFQ Aging: Periodically boost all processes to highest queue
  2. RMS Feasibility: Ensures all tasks meet deadlines
  3. Lottery/Stride: Guarantee minimum CPU share to all processes
  4. RR Queue: No process waits indefinitely

Deadline & Real-Time Analysis

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

Fairness Measurement (Jain's Index)

The simulator calculates Jain's Fairness Index to measure fair CPU allocation:

$$ F = \frac{(\sum_{i=1}^{n} x_i)^2}{n \sum_{i=1}^{n} x_i^2} $$

Where $x_i$ = CPU time received by process $i$

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)

CPU Time Prediction for SJF/SRTF

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

Throughput vs Latency Trade-offs

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

πŸŽ“ Learning Path

Beginner Level (Understanding Basics)

  1. Load simple workload:

    ./scheduler_cli example/sample.json FCFS
    ./scheduler_cli example/sample.json RR --quantum 4
  2. Observe results:

    • Compare Gantt charts
    • Note differences in metrics
    • Understand why FCFS has high waiting times
  3. Interactive exploration (GUI):

    • Load sample.json
    • Try each algorithm
    • Watch visualization

Intermediate Level (Comparative Analysis)

  1. Run experiments:

    ./experiment_runner example/workload_heavy.json output/study1
    ./compare output/study1
  2. Analyze results:

    • Which algorithm minimizes wait time?
    • Which is most fair?
    • What's the throughput ranking?
  3. Modify workloads:

    • Create custom JSON files
    • Vary process count, burst sizes
    • Observe algorithm sensitivity

Advanced Level (Real-Time & Optimization)

  1. Real-time scheduling:

    ./scheduler_cli example/workload_realtime.json EDF
    ./scheduler_cli example/workload_realtime.json RMS
  2. Analyze feasibility:

    • Calculate utilization
    • Predict deadline misses
    • Test near-capacity scenarios
  3. Fair resource allocation:

    ./scheduler_cli example/workload_random.json LOTTERY --tickets
    ./scheduler_cli example/workload_random.json STRIDE --tickets
  4. Performance optimization:

    • Create adversarial workloads
    • Test algorithm limits
    • Generate comparison reports

πŸ” Common Use Cases & Solutions

Use Case 1: Interactive System Scheduler

Goal: Minimize user-perceptible latency

Recommendation: RR or MLFQ

./scheduler_gui  # Use RR with quantum=10 or MLFQ

Why:

  • Both provide good fairness
  • Response time is acceptable
  • No process starves

Use Case 2: Batch Processing System

Goal: Maximize throughput

Recommendation: SJF (if burst times known)

./scheduler_cli workloads/batch_jobs.json SJF

Why:

  • SJF minimizes average waiting time
  • Reduces idle time
  • Good for batch queues

Use Case 3: Real-Time Embedded System

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 EDF

Why:

  • RMS: Optimal for periodic tasks
  • EDF: Optimal for mixed deadlines
  • Both guarantee deadline feasibility with proper configuration

Use Case 4: Multi-Media Server

Goal: Fair resource allocation among clients

Recommendation: STRIDE or LOTTERY

./scheduler_cli workloads/clients.json STRIDE
./scheduler_cli workloads/clients.json LOTTERY

Why:

  • Proportional CPU share
  • No starvation
  • Deterministic fairness (STRIDE) or statistical fairness (LOTTERY)

πŸ“Š Metrics Deep Dive

CPU Utilization

$$ U = \frac{\text{Total Time CPU is Busy}}{\text{Total Makespan}} \times 100% $$

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

Turnaround Time

$$ T_{\text{turnaround}} = \text{Finish Time} - \text{Arrival Time} $$

$$ \text{Average Turnaround} = \frac{1}{n}\sum_{i=1}^{n}(F_i - A_i) $$

What it measures: Total time in system (queue + execution)

Optimization: Minimize for interactive users


Waiting Time

$$ W_i = T_{\text{turnaround}} - \text{CPU Time Received} $$

What it measures: Time wasted waiting in queue

Goal: Minimize, especially for interactive systems

Relationship: Lower waiting time β†’ better response


Response Time

$$ R_i = \text{First Execution Time} - \text{Arrival Time} $$

What it measures: Time until process first gets CPU

Critical for: Interactive systems (shell, GUI)

Goal: Minimize variance and maximum


Fairness (Jain's Index)

$$ F = \frac{(\sum_{i=1}^{n} x_i)^2}{n \sum_{i=1}^{n} x_i^2} $$

Measures: How equally CPU time is distributed

Range: 0 to 1

  • 1.0 = perfect fairness
  • 0.0 = complete unfairness

Use: Compare algorithmic fairness properties


πŸ§ͺ Experimental Design

Experiment Template

// 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/light

Workload Characteristics

Light 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

πŸ’Ύ Data Format Reference

Process JSON Schema

{
    "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
}

Output CSV Format

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
...

πŸš€ Performance Tips & Optimization

Performance Optimization Tips

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

πŸ“š Additional Resources

Research Papers (Citations)

  1. Scheduling Algorithms Foundation

    • Liu & Layland (1973): "Scheduling Algorithms for Multiprogramming in a Hard-Real-Time Environment"
    • Real-time scheduling theory
  2. Proportional-Share Scheduling

    • Waldspurger & Weihl (1994): "Lottery Scheduling: Flexible Proportional-Share Resource Allocation"
    • Waldspurger & Weihl (1995): "Stride Scheduling: Deterministic Proportional-Share Resource Management"
  3. Multi-Level Queue Scheduling

    • Silberschatz et al.: "Operating System Concepts"
    • Chapter on Process Scheduling

External Documentation

Books

  • "Operating Systems: Three Easy Pieces" - Remzi H. Arpaci-Dusseau
  • "Real-Time Systems" - Jane W.S. Liu
  • "Operating System Concepts" - Silberschatz, Galvin, Gagne

πŸ”¬ Verification & Validation

Algorithm Correctness Checklist

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

πŸ› Known Limitations & Future Work

Current Limitations

  1. Single-Core Simulation: Multi-processor scheduling not modeled
  2. Uniform Burst Times: No I/O think time between bursts
  3. Static Workload: No dynamic process creation/termination
  4. No Memory/IO: Only CPU scheduling modeled
  5. Deterministic Simulation: No random variations in burst times
  6. No Migration: Processes don't migrate between queues dynamically

Future Enhancements

  • 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

πŸ“ Troubleshooting Extended Guide

Build Issues

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-json

CMake configure fails:

# Clean build
rm -rf build/
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)

Runtime Issues

"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=OFF

Segmentation 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 values

🎯 Quick Start Cheat Sheet

Installation (5 minutes)

git clone <repo>
cd scheduler-sim
mkdir build && cd build
cmake ..
cmake --build . --config Release

First Simulation (2 minutes)

# GUI
./scheduler_gui

# CLI
./scheduler_cli ../example/sample.json rr --quantum 4

Batch Experiment (1 minute)

./experiment_runner ../example/workload_heavy.json results
./compare results

View Results

# CSV file
cat output/timeline_RR.csv

# HTML comparison
open results/comparison_report.html

πŸ“„ License & Legal

License Information

This 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

Citation

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}
}

πŸŽ‰ Closing Notes

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.

Key Takeaways

  1. Understand algorithms: Visualize how different schedulers behave
  2. Compare performance: Run experiments across algorithms
  3. Optimize systems: Identify best scheduler for your workload
  4. Learn OS concepts: Hands-on exploration of scheduling theory
  5. Research foundation: Extensible platform for new algorithms

Next Steps

  • 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:

οΏ½ References & Resources

Operating Systems Concepts

Implementation References

  • 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)

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages