Production-quality CPU scheduling simulator: FCFS, SJF, SRTF, Priority, Round Robin, MLFQ, EEVDF
Project description
cpusched-ash-win-cpu — CPU Scheduling Simulator
cpusched-ash-win-cpu is a production-quality, zero-dependency Python library for simulating CPU scheduling algorithms. It is designed for operating-systems courses, research, and anyone who needs to compare scheduler behaviour quickly.
Features
| Algorithm | Type |
|---|---|
| FCFS | Non-preemptive |
| SJF | Non-preemptive |
| SRTF | Preemptive (shortest remaining time) |
| Priority | Non-preemptive |
| PriorityPreemptive | Preemptive |
| Round Robin | Preemptive (configurable quantum) |
| MLFQ | Preemptive (configurable levels + boost) |
| EEVDF | Preemptive (Linux 6.6+ default scheduler) |
Metrics computed:
- Waiting time, Turnaround time, Response time (per-process + averages)
- CPU utilization
- Throughput (processes per time unit)
Output formats:
- Text Gantt chart
- Self-contained HTML Gantt chart
- CSV export (process list, metrics, Gantt)
Installation
pip install cpusched-ash-win-cpu
Or install from source:
git clone https://github.com/example/cpusched-ash-win-cpu
cd cpusched-ash-win-cpu
pip install -e ".[dev]"
Quick Start
from cpusched import Process, Simulator
processes = [
Process("P1", arrival_time=0, burst_time=6, priority=2),
Process("P2", arrival_time=2, burst_time=8, priority=1),
Process("P3", arrival_time=4, burst_time=7, priority=3),
]
sim = Simulator(processes)
# Run a single algorithm
result = sim.run("fcfs")
print(result.summary())
# Compare all algorithms
all_results = sim.run_all(rr_quantum=4)
print(sim.compare(all_results))
Output
Algorithm : FCFS
------------------------------------------------------------
PID Arrival Burst Finish WT TAT RT
------------------------------------------------------------
P1 0 6 6 0 6 0
P2 2 8 14 4 12 4
P3 4 7 21 10 17 10
------------------------------------------------------------
Avg Waiting Time : 4.67
Avg Turnaround : 11.67
Avg Response Time : 4.67
CPU Utilization : 100.0%
Throughput : 0.1429 proc/unit
------------------------------------------------------------
Gantt Chart:
| P1 | P2 | P3 |
0 6 14 21
Usage by Algorithm
FCFS
from cpusched import FCFS, Process
result = FCFS([Process("P1", 0, 6), Process("P2", 2, 4)]).run()
SJF / SRTF
from cpusched import SJF, SRTF
result_sjf = SJF(processes).run()
result_srtf = SRTF(processes).run()
Priority (non-preemptive and preemptive)
from cpusched import Priority, PriorityPreemptive
result = Priority(processes).run() # non-preemptive
result = PriorityPreemptive(processes).run() # preemptive
Lower priority value = higher urgency.
Round Robin
from cpusched import RoundRobin
result = RoundRobin(processes, quantum=4).run()
MLFQ
from cpusched import MLFQ
result = MLFQ(
processes,
quantums=[8, 16, 32], # per-level time quanta
boost_interval=50, # 0 = no boost (starvation prevention disabled)
).run()
EEVDF (Linux 6.6+ default)
from cpusched import EEVDF
result = EEVDF(processes, quantum=8).run()
CSV Import / Export
from cpusched import load_processes_csv, save_result_csv, save_gantt_csv
# Load processes from a CSV file
processes = load_processes_csv("processes.csv")
# CSV format
# pid,arrival_time,burst_time,priority
# P1,0,6,2
# P2,2,8,1
# Export metrics
save_result_csv(result, "metrics.csv")
# Export Gantt entries
save_gantt_csv(result, "gantt.csv")
Gantt Chart Rendering
from cpusched import GanttRenderer
renderer = GanttRenderer(result)
# Text chart
print(renderer.text())
# Save HTML chart (self-contained, open in any browser)
renderer.save_html("gantt.html")
Command-Line Interface
# Built-in demo with 5 sample processes
cpusched demo
# Run FCFS on your own CSV
cpusched run --file procs.csv --algo fcfs
# Run all algorithms and compare
cpusched run --file procs.csv --all --quantum 4
# Export to HTML Gantt + CSV metrics
cpusched run --file procs.csv --algo rr --quantum 4 \
--html gantt.html --export metrics.csv
# Aliases accepted
cpusched run --file procs.csv --algo priority_preemptive
cpusched run --file procs.csv --algo round_robin --quantum 3
Running Tests
pip install -e ".[dev]"
pytest tests/ -v --cov=cpusched
Project Structure
cpusched/
├── cpusched/
│ ├── __init__.py # Public API
│ ├── __main__.py # CLI (python -m cpusched)
│ ├── process.py # Process, GanttEntry, SchedulingResult
│ ├── base.py # BaseScheduler, SchedulingResultBuilder
│ ├── simulator.py # Simulator facade
│ ├── gantt.py # text_gantt, html_gantt, GanttRenderer
│ ├── io.py # CSV import/export
│ └── algorithms/
│ ├── __init__.py
│ ├── classic.py # FCFS, SJF, SRTF, Priority, PriorityPreemptive
│ ├── rr_mlfq.py # RoundRobin, MLFQ
│ └── eevdf.py # EEVDF
├── tests/
│ └── test_cpusched.py # ~80 unit tests
├── pyproject.toml
└── README.md
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cpusched_ash_win_cpu-1.0.1.tar.gz.
File metadata
- Download URL: cpusched_ash_win_cpu-1.0.1.tar.gz
- Upload date:
- Size: 25.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd31e8ec2bb18d16c58c9a30873e6d021b3fa027610e02f9c65daf6430985c7f
|
|
| MD5 |
1ad664bc6a218154adfceefb2c13b745
|
|
| BLAKE2b-256 |
86d18d1b239be8a78cbeba269d45de1ed92c86385804570b9ebceaded3e1929a
|
File details
Details for the file cpusched_ash_win_cpu-1.0.1-py3-none-any.whl.
File metadata
- Download URL: cpusched_ash_win_cpu-1.0.1-py3-none-any.whl
- Upload date:
- Size: 23.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82e592a7dc85b8579f2d5e3f912a1aac188220f9f064fd7b48e24f479f3a61e2
|
|
| MD5 |
4b214eacf9a913b6b3444629c33f45d2
|
|
| BLAKE2b-256 |
10e9aa90749c34584b2062890a7c095ce1db4bb9e4212f3e45b05efd19207867
|