This project implements various CPU scheduling algorithms in Python to demonstrate how different scheduling strategies work in operating systems.
This project includes implementations of four fundamental CPU scheduling algorithms:
-
First-Come, First-Served (FCFS)
- Non-preemptive scheduling algorithm
- Processes are executed in the order they arrive
- Simple to implement but may lead to the convoy effect
- Implementation:
fcfs.py
-
Round Robin (RR)
- Preemptive scheduling algorithm
- Each process gets a fixed time quantum
- Provides fair CPU sharing and good response time
- Implementation:
rr.py
-
Shortest Job First (SJF)
- Non-preemptive scheduling algorithm
- Selects the process with the shortest burst time
- Optimal average waiting time but may lead to starvation
- Implementation:
sjf.py
-
Shortest Remaining Time (SRT)
- Preemptive version of SJF
- Switches to shorter processes when they arrive
- Optimal average response time but may lead to starvation
- Implementation:
srt.py
- Make sure you have Python 3.x installed
- Run the main program:
python OS-algorthms.py
- Select the scheduling algorithm you want to test
- Follow the prompts to input:
- Number of processes
- Arrival times
- Burst/Processing times
- Time quantum (for Round Robin only)
OS-algorthms.py: Main program that lets you choose which algorithm to runfcfs.py: First-Come, First-Served implementationrr.py: Round Robin implementationsjf.py: Shortest Job First implementationsrt.py: Shortest Remaining Time implementationOS-lab-reports/: Contains detailed reports and documentation
Each algorithm displays:
- Process execution order
- Gantt chart showing:
- Process ID
- Start time
- End time
Example output:
--------------------------ALGORITHM-------------------------
Process order: P1, P2, P3, P4
Gantt Chart:
P1 --- 0 : 3
P2 --- 3 : 7
P3 --- 7 : 12
P4 --- 12 : 15
- Simple and fair for equal-length processes
- May cause long average waiting times
- No process prioritization
- Fair CPU sharing
- Better response time
- Higher context switching overhead
- Time quantum affects performance
- Optimal average waiting time
- Requires knowing/estimating burst times
- May cause starvation of longer processes
- Preemptive version of SJF
- Optimal average response time
- Higher context switching overhead
- May cause starvation of longer processes