# ๐Ÿ–ฅ๏ธ Process Scheduler Simulator > An interactive educational tool for visualizing and comparing classical CPU scheduling algorithms from Operating Systems. [![React](https://img.shields.io/badge/React-18-61DAFB?logo=react&logoColor=white)](https://react.dev/) [![TypeScript](https://img.shields.io/badge/TypeScript-5-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/) [![Vite](https://img.shields.io/badge/Vite-6-646CFF?logo=vite&logoColor=white)](https://vitejs.dev/) [![Tailwind CSS](https://img.shields.io/badge/Tailwind-4-06B6D4?logo=tailwindcss&logoColor=white)](https://tailwindcss.com/) [![Vitest](https://img.shields.io/badge/Tested_with-Vitest-6E9F18?logo=vitest&logoColor=white)](https://vitest.dev/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) --- ## โœจ What is it? The **Process Scheduler Simulator (PSS)** runs entirely in the browser, completely free of servers and system dependencies. You define the processes, choose the algorithm, and watch the simulation unfold in real time through the Gantt chart. Ideal for: - ๐Ÿ“š Operating Systems students who want to visualize what was once only theory - ๐Ÿ‘ฉโ€๐Ÿซ Instructors looking for an interactive classroom tool - ๐Ÿ” Professionals revisiting OS fundamentals A live demo is available at: **https://pss.lucasrguerra.dev.br/** --- ## ๐Ÿš€ Quick Start ### Prerequisites - [Node.js](https://nodejs.org/) 20+ - npm 10+ ### Local installation and run ```bash # Clone the repository git clone https://github.com/lucasrguerra/pss.git cd pss # Install dependencies npm install # Start the development server npm run dev ``` Open [http://localhost:5173](http://localhost:5173) in your browser. ### Production build ```bash npm run build npm run preview ``` ### With Docker ```bash docker compose up ``` --- ## ๐ŸŽฎ How to use 1. **Create your processes**: In the left panel, add processes by defining name, arrival time, priority, and a sequence of bursts (CPU and I/O). Enable the **Use Threads** toggle to create threads within a process, choosing the model (MANY_TO_ONE, ONE_TO_ONE, or MANY_TO_MANY) and the intra-process policy (FCFS, RR, or Priority). 2. **Configure the scheduler**: Choose an algorithm and adjust the parameters (quantum for RR, aging for Priority, quantums and boost interval for MLFQ, etc.). 3. **Run the simulation**: Use the Play/Pause/Step controls to run the simulation at the speed you want (0.25ร— to 4ร—). 4. **Analyze the results**: The Gantt chart shows each process's state in real time (and its threads, when configured). At the end, the metrics panel displays turnaround, waiting time, throughput, and โ€” in the Threads tab โ€” individual per-thread metrics. > ๐Ÿ’ก **Tip:** Load one of the built-in **presets** to see classic phenomena such as the FCFS convoy effect or priority starvation. --- ## โš™๏ธ Supported Algorithms | Algorithm | Preemptive? | Parameters | |-----------|:-----------:|------------| | **FCFS**: First Come, First Served | โŒ | None | | **SJF**: Shortest Job First | โŒ | None | | **SRTF**: Shortest Remaining Time First | โœ… | None | | **Round Robin (RR)** | โœ… | Quantum | | **Priority NP**: Non-Preemptive Priority | โŒ | Aging (optional) | | **Priority P**: Preemptive Priority | โœ… | Aging (optional) | | **Priority RR**: Priority with Round Robin | โœ… | Quantum + Aging (optional) | | **HRRN**: Highest Response Ratio Next | โŒ | None | | **Multilevel Queue** | โœ… | Quantum per queue | | **MLFQ**: Multilevel Feedback Queue | โœ… | Quantums per queue + boost interval | > See the [algorithms documentation](./docs/algorithms.en.md) for details on how each one works. --- ## ๐Ÿ“Š Computed Metrics For each simulated process, PSS automatically computes: - **Response Time**: time until the first CPU usage - **Turnaround Time**: total time from arrival to completion - **Waiting Time**: total time spent in the Ready queue - **CPU Time / I/O Time**: effective time in each type of burst - **CPU Utilization**: percentage of turnaround time spent on CPU - **Bound Type**: automatic classification as CPU Bound, I/O Bound, or Balanced Globally: averages for response/turnaround/waiting, throughput, and overall CPU utilization. --- ## ๐Ÿ—‚๏ธ Project Structure ``` src/ โ”œโ”€โ”€ core/ # Pure logic (no React) โ”‚ โ”œโ”€โ”€ algorithms/ # Implementation of each algorithm โ”‚ โ”‚ โ”œโ”€โ”€ base.ts # Abstract class BaseScheduler โ”‚ โ”‚ โ”œโ”€โ”€ fcfs.ts โ”‚ โ”‚ โ”œโ”€โ”€ sjf.ts โ”‚ โ”‚ โ”œโ”€โ”€ rr.ts โ”‚ โ”‚ โ”œโ”€โ”€ priority.ts โ”‚ โ”‚ โ”œโ”€โ”€ priority_rr.ts โ”‚ โ”‚ โ”œโ”€โ”€ hrrn.ts โ”‚ โ”‚ โ”œโ”€โ”€ multilevel.ts โ”‚ โ”‚ โ”œโ”€โ”€ mlfq.ts # Multilevel Feedback Queue โ”‚ โ”‚ โ””โ”€โ”€ index.ts # Dispatch by algorithm โ”‚ โ”œโ”€โ”€ engine.ts # SimulationEngine, orchestrates the ticks (thread-aware) โ”‚ โ”œโ”€โ”€ thread-scheduler.ts # Intra-process scheduler (FCFS / RR / Priority) โ”‚ โ”œโ”€โ”€ metrics.ts # Per-process, global, and per-thread metrics computation โ”‚ โ”œโ”€โ”€ types.ts # All TypeScript interfaces โ”‚ โ””โ”€โ”€ presets.ts # Pre-defined scenarios (processes and threads) โ”‚ โ”œโ”€โ”€ store/ # Global state with Zustand โ”œโ”€โ”€ components/ # React components โ”‚ โ”œโ”€โ”€ ProcessPanel/ # Process creation and editing โ”‚ โ”‚ โ”œโ”€โ”€ ThreadEditor.tsx # Thread editor (model, policy, per-thread bursts) โ”‚ โ”‚ โ””โ”€โ”€ ... โ”‚ โ”œโ”€โ”€ SchedulerPanel/ # Algorithm selection and parameters โ”‚ โ”œโ”€โ”€ ControlBar/ # Play, Pause, Step, Reset, speed โ”‚ โ”œโ”€โ”€ GanttChart/ # Interactive Gantt chart โ”‚ โ”‚ โ”œโ”€โ”€ GanttThreadRow.tsx # Thread sub-row in the Gantt chart โ”‚ โ”‚ โ””โ”€โ”€ ... โ”‚ โ”œโ”€โ”€ MetricsPanel/ # Table, charts, and global metrics โ”‚ โ”‚ โ”œโ”€โ”€ ThreadMetricsTable.tsx # Per-thread metrics table โ”‚ โ”‚ โ””โ”€โ”€ ... โ”‚ โ””โ”€โ”€ shared/ # Buttons, badges, tooltips, modals โ”‚ โ”œโ”€โ”€ threadUtils.ts # Thread color derivation (HSL) โ”‚ โ””โ”€โ”€ ... โ”‚ โ””โ”€โ”€ hooks/ # Custom hooks (animation loop, export, etc.) ``` --- ## ๐Ÿ“ฆ Available Presets Load classic scenarios with a single click to explore OS phenomena: **Processes:** | Preset | What it demonstrates | |--------|----------------------| | `classic_fcfs` | Basic execution with FCFS, no I/O | | `convoy_effect` | Convoy effect: one long process blocking many short ones | | `rr_demo` | Fair time-sharing with Round Robin (quantum=3) | | `starvation` | Low-priority processes never receive CPU | | `aging_fix` | The same starvation scenario, solved with aging | | `io_heavy` | Mix of CPU Bound vs. I/O Bound processes | | `multilevel_demo` | Multiple queues with different priorities | **Threads:** | Preset | What it demonstrates | |--------|----------------------| | `many_to_one` | N:1 model โ€” any thread's I/O blocks the entire process | | `one_to_one` | 1:1 model โ€” threads block independently | | `many_to_many` | N:M model โ€” kernel slots limit parallelism | | `thread_starvation` | Intra-process starvation with Priority policy | | `threads_vs_processes` | Direct comparison: threaded process vs single-burst process | --- ## ๐Ÿงช Tests ```bash # Run all unit tests npm test # Watch mode (re-runs on save) npm run test:watch # With coverage report npm run test:coverage ``` Tests cover the simulation engine, all scheduling algorithms, and metrics computation. --- ## ๐Ÿ› ๏ธ Technology Stack | Layer | Technology | |-------|-----------| | UI Framework | React 18 | | Language | TypeScript 5 | | Build tool | Vite 6 | | Styling | Tailwind CSS 4 | | Global state | Zustand 5 | | Charts | Recharts | | Icons | Lucide React | | Testing | Vitest + Testing Library | --- ## ๐Ÿ“„ Additional Documentation - [๐Ÿ“ Scheduling Algorithms](./docs/algorithms.en.md): detailed description of each algorithm, tie-breaking rules, and examples - [๐Ÿ“ Metrics](./docs/metrics.en.md): formulas and definitions for all computed metrics - [๐Ÿ“ JOSS Paper](./paper.md): scientific paper submitted to the Journal of Open Source Software *Tambรฉm disponรญvel em: [๐Ÿ‡ง๐Ÿ‡ท Portuguรชs](./README.md)* --- ## ๐Ÿค Contributing Contributions are welcome! Please read our [CONTRIBUTING.md](./CONTRIBUTING.md) guide for details on our code of conduct, and the process for submitting Pull Requests to us. --- ## ๐Ÿ“œ License Distributed under the [MIT License](./LICENSE). Developed by [Lucas Rayan Guerra](https://github.com/lucasrguerra).