Skip to content

ASADI-vc/OS-Scheduling-Algorithms-Visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OS Scheduling Visualizer

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.


Features

  • 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 MEAN row with Mean WT and Mean TAT
    • Zoomable/pannable Gantt chart (Matplotlib toolbar)
    • A legend showing a unique color for each 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


Prerequisites

  • Python 3.8+ (3.10 recommended)
  • conda (recommended) or mamba (optional)

Required Python packages:

  • matplotlib
  • tk/tcl (for tkinter) — provided by the system or installable via conda

Setup (recommended: 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 matplotlib

Or with mamba (faster resolver):

mamba create -n os_scheduler python=3.10 matplotlib tk -c conda-forge -y
mamba activate os_scheduler

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

Files

  • 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

How to run

From the activated environment, run:

python appV4.py

If you use a different name for the file (e.g. appV3.py), run that instead:

python appV3.py

Fullscreen and shortcuts

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

Quick usage guide

  1. Add processes: Enter Arrival, Burst, and Priority, then click Add Process. Repeat for all processes.
  2. Set parameters: Enter Context Switch time and Time Quantum (RR) if using Round Robin.
  3. Select algorithms: Choose which algorithms to run using the checkboxes.
  4. Run: Click Run Selected.
  5. Inspect results: Each algorithm appears in its own tab. The table contains per-process WT/TAT/CT and a MEAN row. The Gantt chart is below the table and can be zoomed/panned using the Matplotlib toolbar (zoom, pan, reset, save).
  6. Comparison: Open the Comparison tab to see mean WT & TAT across algorithms.

Notes about context switching

  • 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_switch routine shifts subsequent schedule segments when context switch time is added so the timeline remains correct.

UI / Styling

  • Uses ttk (clam theme) and custom styles to make buttons and tables visually clearer.
  • Each process gets a distinct color (from Matplotlib's tab20 palette). The color legend appears in each algorithm tab.
  • Charts are placed under each algorithm table to improve reading flow.

Troubleshooting

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

Extending the app

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.

License

This project is provided as-is for educational purposes. Feel free to reuse and adapt for teaching. No warranty.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages