This is a CPU scheduler simulator that simulates the behavior of different CPU scheduling algorithms. The simulator is written in Python and uses matplotlib to plot the results. Following algorithms are implemented:
- First Come First Serve (FCFS) or First In First Out (FIFO)
- Shortest Job First (SJF) (Preemptive)
- Shortest Job First (SJF) (Non-Preemptive)
- Round Robin (RR)
- Priority (Preemptive)
- Priority (Non-Preemptive)
After cloning the repository and setting up the environment, you can run the simulator can be run by executing the following command:
python3 simulate.py -a <algorithm> -p <processes.json>The following arguments are available:
-a <algorithm>: The scheduling algorithm to use. Possible values areFIFO,PreemptiveSJF,NonPreemptiveSJF,RR,PreemptivePriorityandNonPreemptivePriority.-p <processes.json>: The path to the JSON file containing the processes to schedule. See the section below for more information.
The processes JSON file contains the processes to schedule. It is a JSON array of objects. Each object represents a process and has the following properties:
pid: The process ID. This is a string.arrival_time: The arrival time of the process. This is an integer.burst_time: The burst time of the process. This is an integer.priority: The priority of the process. This is an integer. This property is only required for the priority algorithms. Smaller values indicate higher priority.
[
{
"pid": "P1",
"arrival_time": 0,
"burst_time": 5,
"priority": 1
},
{
"pid": "P2",
"arrival_time": 1,
"burst_time": 3,
"priority": 2
},
{
"pid": "P3",
"arrival_time": 2,
"burst_time": 2,
"priority": 3
}
]The simulator will output the following information:
- The average waiting time
- The average turnaround time
- The average response time
- Throughput
- CPU utilization
- A box plot for three metrics:
- Waiting time
- Turnaround time
- Response time
The simulator requires Python 3.6 or higher. Required Python packages are listed in requirements.txt.
They can be installed by executing the following command:
pip3 install -r requirements.txtContributions are welcome. Please open an issue or a pull request. Read below for information on how to add a new algorithm.
To add a new algorithm, follow these steps:
- Create a new class in
algorithmsmodule that inherits fromBaseAlgorithm. - Set
process_compare_propto the property that is used to compare processes. - Implement the
runmethod. - Import the new algorithm in
algorithms/__init__.py.
This project is licensed under the MIT License - see the LICENSE file for details.