Skip to content
ankan123basuPublic

About

An interactive AI based CPU scheduling algorithm simulator that demonstrates various scheduling algorithms including FCFS, SJF, Round Robin, and Priority Scheduling. It also demonstrates real-time system monitoring, AI-driven recommendations, and 3D process visualization

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

CPUXpert — Intelligent CPU Scheduling Simulator

Tests codecov Python 3.10+ scikit-learn

A desktop CPU scheduling simulator featuring a real ML-based algorithm recommender (91.5% accuracy), real system monitoring via psutil, and a 54-test pytest suite verified against OS textbook examples.


Features

Scheduling Algorithms — scheduler.py

Six classic scheduling algorithms implemented in the Scheduler class:

Algorithm Method Preemptive Description
FCFS fcfs() No First Come First Served — processes run in arrival order
SJF sjf() No Shortest Job First — picks the shortest burst time among available processes
SRTF sjf_preemptive() Yes Shortest Remaining Time First — re-evaluates at every time unit
Round Robin round_robin(q) Yes Time-sliced with configurable quantum
Priority priority() No Higher value = higher priority
Priority (Pre) priority_preemptive() Yes Preempts when a higher-priority process arrives

ML Algorithm Recommender — ml_recommender.py

A trained Random Forest classifier that predicts the best scheduling algorithm for any workload.

How it works:

2,000 Random Workloads → Run All 6 Algorithms → Label Best → Extract 8 Features → Train Classifier

Training results (printed by python ml_recommender.py, fully reproducible with seed=42):

Model Selected:        Random Forest (200 estimators, max_depth=15)
5-Fold CV Accuracy:    90.88% ± 0.98%
Test Accuracy:         91.50%
Test F1 (weighted):    91.35%
Test F1 (macro):       77.70%

Per-class performance:

Class Precision Recall F1-Score Support
FCFS 1.00 0.33 0.50 3
SJF 0.94 0.87 0.90 181
SRTF 0.90 0.96 0.93 216

Confusion matrix:

Predicted →   FCFS   SJF   SRTF
Actual FCFS  [  1     2     0  ]
Actual SJF   [  0   157    24  ]
Actual SRTF  [  0     8   208  ]

Feature importances:

Feature Importance
arrival_spread 31.52%
arrival_var 31.28%
burst_arrival_ratio 15.28%
burst_cv 5.83%
burst_var 5.62%
burst_mean 4.39%
priority_var 3.13%
process_count 2.95%

Label distribution across 2,000 workloads (ground truth — which algorithm actually wins):

Algorithm Count Percentage
SRTF 1,083 54.1%
SJF 903 45.1%
FCFS 14 0.7%
Priority / Round Robin 0 0.0%

SRTF and SJF dominate because they minimize waiting time by design. Priority and Round Robin optimize for fairness, not waiting time.

Real System Monitoring — task_manager.py

The Performance Monitor reads real system stats using psutil:

Metric Source Unit
CPU psutil.cpu_percent() % (0–100)
Memory psutil.virtual_memory().percent % (0–100)
Disk I/O psutil.disk_io_counters() delta MB/s
Network I/O psutil.net_io_counters() delta Mbps

Sampled every 1 second. Plotted as 60-second rolling history. Zero random number generation in the monitoring code.

Process Control — task_manager.py

Action What it does
Pause Adds PID to paused_pids; process is skipped in scheduling
Resume Removes PID from paused_pids; process re-enters scheduling
Terminate Sets remaining_time = 0 and marks completion_time on the Process object

These modify actual scheduler.Process state — not cosmetic.


Test Suite

54 tests, 100% passing — verified with python -m pytest -v:

tests/test_scheduler.py       — 35 tests (algorithm correctness + edge cases + metrics)
tests/test_ml_recommender.py  — 19 tests (workload gen + features + labeler + prediction)

Coverage:

Module Statements Covered Coverage
scheduler.py 239 205 86%
ml_recommender.py 238 131 55%
test_scheduler.py 182 177 97%
test_ml_recommender.py 124 119 96%

Textbook-verified test cases include:

  • FCFS: P1(0,24), P2(0,3), P3(0,3) → WT: [0, 24, 27], Avg WT = 17.0
  • SJF: P1(0,6), P2(0,8), P3(0,7), P4(0,3) → WT: [3, 16, 9, 0], Avg WT = 7.0
  • SRTF: P1(0,8), P2(1,4), P3(2,9), P4(3,5) → WT: [9, 0, 15, 2], Avg WT = 6.5
  • Round Robin (q=4): P1(0,24), P2(0,3), P3(0,3) → WT: [6, 4, 7]
  • Priority: P1-P5 with priorities 3,1,4,5,2 → order: P4→P3→P1→P5→P2
  • Edge cases: single process, all-same-arrival, all-same-burst, priority ties, CPU gaps

CI pipeline (.github/workflows/test.yml): runs on every push/PR across Python 3.10, 3.11, 3.12.


Tech Stack

Component Technology
Language Python 3.10+
GUI Tkinter
Visualization Matplotlib
Numerical NumPy
Machine Learning scikit-learn (Random Forest)
System Monitoring psutil
Model Persistence joblib
Testing pytest + pytest-cov
CI/CD GitHub Actions

Quick Start

# Clone
git clone https://github.com/ankan123basu/CPUXpert.git
cd CPUXpert

# Virtual environment
python -m venv .venv
.venv\Scripts\activate        # Windows
# source .venv/bin/activate   # Linux/Mac

# Install
pip install -r requirements.txt

# Train the ML model (first time only — takes ~40s)
python ml_recommender.py

# Run the simulator
python main.py

Running Tests

python -m pytest --cov=. --cov-report=term-missing -v

Running Benchmarks

python benchmark.py

Project Structure

CPUXpert/
├── main.py                    # Tkinter GUI application
├── scheduler.py               # 6 scheduling algorithms
├── ml_recommender.py          # ML training pipeline + prediction API
├── task_manager.py            # psutil monitoring + process control
├── benchmark.py               # Algorithm benchmarking
├── requirements.txt           # Dependencies
├── pytest.ini                 # Test configuration
├── .gitignore
├── ml_model/                  # Generated by ml_recommender.py
│   ├── model.pkl              #   Trained Random Forest (200 trees)
│   ├── scaler.pkl             #   StandardScaler
│   └── metadata.json          #   Accuracy, F1, config
├── tests/
│   ├── test_scheduler.py      # 35 algorithm tests
│   └── test_ml_recommender.py # 19 ML module tests
└── .github/workflows/
    └── test.yml               # CI on Python 3.10/3.11/3.12

Scope & Limitations

  • This is a desktop simulator — not a web app, not deployed to cloud
  • The ML model is a Random Forest, not deep learning
  • It simulates OS scheduling — it does not schedule real OS processes
  • System monitoring shows your machine's real stats but does not control them

About

An interactive AI based CPU scheduling algorithm simulator that demonstrates various scheduling algorithms including FCFS, SJF, Round Robin, and Priority Scheduling. It also demonstrates real-time system monitoring, AI-driven recommendations, and 3D process visualization

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages