This project is a simulation of various CPU scheduling algorithms implemented in Python. It aims to deepen understanding of CPU scheduling by simulating process generation, applying scheduling algorithms, and measuring performance using both preemptive and non-preemptive scheduling techniques.
- Introduction
- Features
- Directory Structure
- Prerequisites
- Installation
- Usage
- Modules Description
- Simulation Output
- Visualization
- Shortcuts
- Contact
The simulation generates 20 processes with random arrival and burst times. Each scheduling algorithm is tested in both preemptive and non-preemptive modes (where applicable). The performance of each algorithm is measured using metrics such as average turnaround time, average waiting time, CPU utilization, and throughput.
- Implementation of the following CPU scheduling algorithms:
- First-Come, First-Served (FCFS)
- Shortest Job First (SJF) (Preemptive and Non-Preemptive)
- Round Robin (RR)
- Priority Scheduling (Preemptive and Non-Preemptive)
- Multilevel Queue Scheduling
- Simulation of process generation with random arrival and burst times
- Performance measurement and comparison for each algorithm
- Visualization of performance metrics using matplotlib
├── README.md
├── algorithm.py # Contains scheduling algorithms
├── main.py # Entry point of the simulation
├── metric.py # Performance metrics calculation
├── schema.py # Data classes for processes and performance
└── utils.py # Utility functions
- Python 3.6 or higher
- Clone the repository:
git clone https://github.com/Kamran151199/cpu-scheduling-simulation.git- Navigate to the project directory:
cd cpu-scheduling-simulation- Install required packages:
pip install -r requirements.txtRun the main script to execute the simulation:
python main.pyThis will:
- Generate 20 processes with random attributes
- Run each scheduling algorithm
- Calculate and display performance metrics
- Generate and display comparison charts for the metrics
main.py: The entry point of the simulation. It orchestrates the process generation, algorithm execution, and results visualizationalgorithm.py: Contains implementations of the CPU scheduling algorithmsmetric.py: Defines functions to calculate performance metricsschema.py: Contains data classes (Process and Performance) representing the processes and performance metricsutils.py: Provides utility functions used across the simulation (e.g., proper naming from variables, process generation)
After running the simulation, you will see:
- Performance metrics printed on the console for each algorithm
- Bar charts comparing the algorithms based on:
- Average Waiting Time
- Average Turnaround Time
- CPU Utilization
- Throughput
The simulation uses matplotlib to generate bar charts that visually compare the performance of different scheduling algorithms.
Example chart:
Note: The actual images will be generated when you run the simulation.
To quickly get started:
- Run Simulation:
python main.py- Modify Process Generation:
- Edit the
generate_processes()function inutils.pyto change the number of processes or the range of arrival and burst times
- Edit the
- Adjust Time Quantum:
- In
algorithm.py, you can adjust thetime_quantumvariable in the Round Robin and Multilevel Queue scheduling functions
- In
For any questions or suggestions, please contact:
- Name: Komron Valijonov
- Email: komron.valijonov@ue-germany.de
