This Flask web application provides an API for executing various process scheduling algorithms. You can use this API to simulate different scheduling strategies for a set of processes and analyze their performance. It was made using the source code of another project of mine.
The simulator supports the following algorithms:
- FCFS: First Come First Serve
- SJF: Shortest Job First
- SRTF: Shortest Remaining Time First
- RR: Round Robin
- PRIOc: Priority (Cooperative)
- PRIOp: Priority (Preemptive)
- Clone the repository to your local machine.
git clone https://github.com/c-sant/process-scheduler-api.git
- Access the project directory.
cd process-scheduler-api
- Create a virtual environment (optional, but recommended):
python -m venv venv
- Activate your virtual environment:
- For Windows:
venv\Scripts\activate
- For macOS and Linux:
source venv/bin/activate
- Install project dependencies:
pip install -r requirements.txt
- Start the application using Flask:
flask run
You can also start by using Python to read the main script file:
python app.py
- Make a POST request to the root endpoint (
/
) with a JSON payload that specifies the scheduling algorithm and the details of the processes to be scheduled. Here's an example of a valid request:
{
"algorithm": "FCFS",
"n_of_processes": 2,
"name": ["p1", "p2"],
"arrival_time": [0, 1],
"execution_time": [5, 2],
"priority_level": [2, 1],
"quantum_length": 2,
"reversed": true
}
algorithm
: the acronym of the algorithm you intend to use. Refer to Implemented Algorithms.n_of_processes
: any positive integer.name
: name of each process. Should be a list with as many items as specified byn_of_processes
.arrival_time
: arrival time of each process. Should be a list with as many items as specified byn_of_processes
.execution_time
: execution/burst time of each process. Should be a list with as many items as specified byn_of_processes
.priority_level
: level of priority of each process. Should be a list with as many items as specified byn_of_processes
.quantum_length
: the quantum length used by the Round Robin algorithm.reversed
: if true, priority levels will follow a descending order.
- The response should have the following structure:
{
"average_turnaround_time": 5.5,
"average_wait_time": 2.0,
"n_of_processes": 2,
"total_execution_time": 7
}
Here's an example of how to use the API with Python and the requests
library:
import requests
url = "http://localhost:5000"
data = {
"algorithm": "FCFS",
"n_of_processes": 3,
"name": ["P1", "P2", "P3"],
"execution_time": [8, 4, 6],
"priority_level": [2, 1, 3],
"arrival_time": [0, 0, 0],
}
response = requests.post(url, json=data)
if response.status_code == 200:
results = response.json()
# Process the scheduling results here
else:
print(f"Error: {response.json()['message']}")
This is a college assignment, but if you would like to contribute and turn this into a real project, please open an issue or submit a pull request.