A comprehensive CPU scheduling simulator implementing FCFS, SJF, Priority, and Round Robin algorithms
Project description
Mini OS CPU Scheduler
A comprehensive CPU scheduling simulator implemented in Python that demonstrates core operating systems concepts. This package simulates and compares multiple CPU scheduling algorithms with detailed metrics and analysis.
🎯 Features
This simulator implements four fundamental CPU scheduling algorithms:
- First-Come, First-Serve (FCFS) - Non-preemptive, executes processes in arrival order
- Shortest Job First (SJF) - Non-preemptive, selects shortest available job
- Priority Scheduling - Non-preemptive, executes highest priority process first
- Round Robin (RR) - Preemptive, uses time quantum for fair scheduling
For each algorithm, the simulator calculates:
- Start time
- Finish time
- Waiting time
- Turnaround time
- Average waiting time
- Average turnaround time
🚀 Installation
Install from PyPI:
pip install mini-os-scheduler
For web dashboard support:
pip install "mini-os-scheduler[web]"
📖 Quick Start
Command Line Interface
After installation, use the mini-scheduler command:
# Run all algorithms with sample data
mini-scheduler --sample --algorithm all
# Run specific algorithm
mini-scheduler --sample --algorithm fcfs
mini-scheduler --sample --algorithm sjf
mini-scheduler --sample --algorithm priority
mini-scheduler --sample --algorithm rr --quantum 3
# Load from JSON file
mini-scheduler --file processes.json --algorithm all
# Load from CSV file
mini-scheduler --file processes.csv --algorithm sjf
Python API
from mini_os_scheduler import Process, compare_algorithms
# Create processes
processes = [
Process(pid=1, arrival_time=0, burst_time=5, priority=2),
Process(pid=2, arrival_time=1, burst_time=3, priority=1),
Process(pid=3, arrival_time=2, burst_time=8, priority=3),
]
# Compare all algorithms
results = compare_algorithms(processes, time_quantum=2)
# Access results
for name, result in results.items():
print(f"{name}:")
print(f" Avg Waiting Time: {result.avg_waiting_time:.2f}")
print(f" Avg Turnaround Time: {result.avg_turnaround_time:.2f}")
for r in result.results:
print(f" PID {r.pid}: Start={r.start_time}, Finish={r.finish_time}")
Input File Formats
JSON Format (processes.json):
[
{"pid": 1, "arrival_time": 0, "burst_time": 5, "priority": 2},
{"pid": 2, "arrival_time": 1, "burst_time": 3, "priority": 1},
{"pid": 3, "arrival_time": 2, "burst_time": 8, "priority": 3}
]
CSV Format (processes.csv):
pid,arrival_time,burst_time,priority
1,0,5,2
2,1,3,1
3,2,8,3
📊 Example Output
================================================================================
Algorithm: FCFS
================================================================================
PID Arrival Burst Priority Start Finish Waiting Turnaround
--------------------------------------------------------------------------------
1 0 5 2 0 5 0 5
2 1 3 1 5 8 4 7
3 2 8 3 8 16 6 14
4 3 6 2 16 22 13 19
5 4 4 1 22 26 18 22
--------------------------------------------------------------------------------
Average 8.20 13.40
================================================================================
🌐 Web Dashboard
Start the interactive web dashboard:
python -m mini_os_scheduler.web.app
Then open your browser to http://localhost:5000
Note: Requires mini-os-scheduler[web] installation.
🧪 Testing
Run the test suite:
# Install development dependencies
pip install "mini-os-scheduler[dev]"
# Run tests
pytest tests/ -v
🏗️ Architecture
The package follows clean software engineering principles:
mini_os_scheduler/
├── models.py # Process data models (Process, ProcessResult)
├── algorithms.py # Core scheduling algorithm implementations
├── simulator.py # Simulation runner and metrics calculation
├── main.py # CLI entry point
└── web/ # Optional Flask web dashboard
├── app.py
└── templates/
Design Principles
- Type Hints: Full type annotations for better code clarity and IDE support
- Docstrings: Comprehensive documentation for all functions
- Modularity: Each component has a single, well-defined responsibility
- Testability: Comprehensive test suite validating algorithm correctness
📈 Use Cases
- Education: Teaching operating systems concepts
- Research: Comparing scheduling algorithm performance
- Development: Understanding CPU scheduling behavior
- Portfolio: Demonstrating systems programming knowledge
🔧 Technical Details
Algorithm Implementations
- FCFS: Simple queue-based execution in arrival order
- SJF: Greedy selection of shortest available job at each decision point
- Priority: Selection based on priority value (lower = higher priority)
- Round Robin: Preemptive scheduling with circular queue and time slicing
Requirements
- Python 3.7 or higher
- No external dependencies (core package)
- Flask 2.0+ (for web dashboard, optional)
📝 License
This project is licensed under the MIT License - see the LICENSE file for details.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
🔗 Links
- PyPI: https://pypi.org/project/mini-os-scheduler/
- GitHub: https://github.com/Karkibinod/mini-os-scheduler
- Issues: https://github.com/Karkibinod/mini-os-scheduler/issues
A CPU scheduling simulator demonstrating systems programming concepts and software engineering best practices.
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 mini_os_scheduler-0.1.0.tar.gz.
File metadata
- Download URL: mini_os_scheduler-0.1.0.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60003918b209f10d133a6b2cc5bd31c97965e914ebc164818dbd2409cb2cebf5
|
|
| MD5 |
05c88869fdce61502248c4960d7bae4e
|
|
| BLAKE2b-256 |
38d96867404ee6248fc860e4bcd3fa007c447d9899db30c427b3d810d9a57663
|
File details
Details for the file mini_os_scheduler-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mini_os_scheduler-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7063bd411b0fb68ab8c63af15fac78d3c592cfaeda5b6f25457a8c50fd2bb6d6
|
|
| MD5 |
78a9c3406babb0d3ac3081492fd0ef1a
|
|
| BLAKE2b-256 |
45abadd50e65c4bde5831af802f74fa438fcbb753d90ad3bdf84edf8c22012ab
|