A simple educational desktop app (Tkinter + Matplotlib) to visualize and compare CPU scheduling algorithms for an Operating Systems course. The app lets you input processes, configure context-switch time and round-robin quantum, run multiple scheduling algorithms, and inspect zoomable Gantt charts and per-process statistics.
-
GUI built with Tkinter (ttk) and Matplotlib.
-
Algorithms implemented:
- FCFS (First-Come, First-Served)
- SJF (Shortest Job First) — non-preemptive
- SRTF (Shortest Remaining Time First) — preemptive
- Priority (non-preemptive)
- Priority (preemptive)
- Round Robin (configurable quantum)
-
Context switch time properly applied and cumulatively shifts later segments.
-
Per-algorithm tabs with:
- Table of per-process
WT(Waiting Time),TAT(Turnaround Time), completion time - A
MEANrow with Mean WT and Mean TAT - Zoomable/pannable Gantt chart (Matplotlib toolbar)
- A legend showing a unique color for each process
- Table of per-process
-
Comparison tab showing mean WT and mean TAT for all run algorithms
-
Scrollable UI (works on small screens) and styled controls for better readability
- Python 3.8+ (3.10 recommended)
conda(recommended) ormamba(optional)
Required Python packages:
matplotlibtk/tcl(fortkinter) — provided by the system or installable via conda
Open an Anaconda/Miniconda shell and run:
# Create and activate environment (uses conda-forge for reliable tk/matplotlib packages)
conda create -n os_scheduler python=3.10 matplotlib tk -c conda-forge -y
conda activate os_scheduler
# (Optional) if matplotlib missing after env creation:
# pip install matplotlibOr with mamba (faster resolver):
mamba create -n os_scheduler python=3.10 matplotlib tk -c conda-forge -y
mamba activate os_schedulerIf you prefer system Python + pip (not recommended for Windows without tkinter):
python -m pip install matplotlib
# Ensure tkinter is available (usually preinstalled on many Linux/macOS distros)appV4.py— main application file (or the Python filename you saved from this project).README.md— this file.- appV#.py — other versions of the application
From the activated environment, run:
python appV4.pyIf you use a different name for the file (e.g. appV3.py), run that instead:
python appV3.py- The app supports toggling fullscreen using F11 and exiting fullscreen with Esc (if that feature was enabled in your build).
- You can also maximize the window manually.
- Add processes: Enter
Arrival,Burst, andPriority, then click Add Process. Repeat for all processes. - Set parameters: Enter
Context Switchtime andTime Quantum (RR)if using Round Robin. - Select algorithms: Choose which algorithms to run using the checkboxes.
- Run: Click Run Selected.
- Inspect results: Each algorithm appears in its own tab. The table contains per-process WT/TAT/CT and a
MEANrow. The Gantt chart is below the table and can be zoomed/panned using the Matplotlib toolbar (zoom, pan, reset, save). - Comparison: Open the Comparison tab to see mean WT & TAT across algorithms.
- Context switch time is inserted each time the scheduler switches from one PID to another when the CPU is busy (and when a switch occurs exactly at the previous end time). The algorithm preserves idle gaps — a context switch is not forcibly inserted earlier than a process start if the CPU was idle in between.
- The
insert_context_switchroutine shifts subsequent schedule segments when context switch time is added so the timeline remains correct.
- Uses
ttk(clam theme) and custom styles to make buttons and tables visually clearer. - Each process gets a distinct color (from Matplotlib's
tab20palette). The color legend appears in each algorithm tab. - Charts are placed under each algorithm table to improve reading flow.
- Matplotlib toolbar errors (TclError about pack/grid): Ensure the version of the app uses a separate frame for the toolbar (this code does). If you see errors, update to the most recent version of the script where toolbar frames are created separately.
- Tkinter missing on Windows: Use the conda command above (
tk -c conda-forge) to install a working tkinter. - Charts clipped or too small: Use the Matplotlib toolbar's Zoom tool and Pan to inspect. The UI is scrollable if your screen is small.
Ideas you might want to add:
- Save/export per-algorithm CSV of stats.
- Export Gantt charts as PNG/SVG via the toolbar (already supported by Matplotlib's Save tool).
- Pre-defined scenario presets for lecture demos.
- Dark theme / ttkbootstrap integration.
- Edit processes inline in the table.
This project is provided as-is for educational purposes. Feel free to reuse and adapt for teaching. No warranty.