CPU scheduling algorithms are crucial for managing how processes are assigned to the CPU for execution. Effective scheduling maximizes CPU utilization, minimizes wait time, and ensures fair resource distribution among processes. Here’s an in-depth look at various CPU scheduling algorithms and key terms used in scheduling:
To get started, first clone the repository:
git clone https://github.com/shivam6862/cpu-scheduling-algorithms
cd cpu-scheduling-algorithms
The frontend is built using Nextjs and requires Node.js to run. Follow these steps to set up and start the frontend development server:
-
Navigate to the
frontend
directory:cd frontend
-
Install the necessary dependencies and start the development server:
npm install npm run build npm start
-
After running the commands, the server will start, and the application will be accessible at
http://localhost:3000
The backend is implemented in Python. It uses a virtual environment for managing dependencies. Follow these steps to set up the backend:
-
Create a virtual environment:
python -m venv .venv
-
Activate the virtual environment:
-
On Windows:
./venv/Scripts/activate
-
On macOS/Linux:
source .venv/bin/activate
-
-
Install the required Python packages:
pip install -r requirements.txt
-
Run the backend application:
python main.py
-
After running the commands, the server will start, and the application will be accessible at
http://localhost:5000
-
First Come First Serve (FCFS):
- Description: Processes are executed in the order they arrive in the ready queue.
- Advantages:
- Simple to implement.
- Predictable as the order of execution is straightforward.
- Disadvantages:
- Can lead to long waiting times, especially for shorter processes if a long process arrives first (Convoy effect).
- Not suitable for time-sharing systems.
-
Shortest Job First (SJF):
- Description: Executes the process with the shortest burst time first.
- Advantages:
- Minimizes average waiting time and turnaround time.
- Disadvantages:
- Difficult to predict the burst time accurately.
- Can lead to starvation if short processes keep arriving.
-
Round Robin (RR):
- Description: Each process gets a fixed time slice (quantum) in a cyclic order.
- Advantages:
- Fair allocation of CPU time.
- Good for time-sharing systems as it ensures no process waits too long.
- Disadvantages:
- Average waiting time can be high.
- Performance heavily depends on the length of the time quantum.
-
Pre-emptive Priority Scheduling:
- Description: Processes are assigned priorities, and the CPU is allocated to the process with the highest priority. If a new process arrives with a higher priority than the current running process, the CPU is preempted and assigned to the new process.
- Advantages:
- Can ensure important processes get more CPU time.
- Disadvantages:
- Can lead to starvation of low-priority processes.
- Priority inversion can occur, where a high-priority process is waiting for a lower-priority one.
-
Arrival Time:
- Definition: The time at which a process arrives in the ready queue.
- Example: If a process arrives at the system at 0 seconds, its arrival time is 0.
-
Burst Time:
- Definition: The total time required by a process for its execution on the CPU.
- Example: If a process needs 5 seconds of CPU time to complete, its burst time is 5 seconds.
-
Completion Time:
- Definition: The time at which a process completes its execution and exits the CPU.
- Example: If a process starts at 2 seconds and finishes at 7 seconds, its completion time is 5 seconds.
-
Turnaround Time:
- Definition: The total time taken by a process from arrival to completion. It is calculated as:
- Example: If a process arrives at 0 seconds and completes at 10 seconds, its turnaround time is 10 seconds.
- Definition: The total time taken by a process from arrival to completion. It is calculated as:
-
Waiting Time:
- Definition: The total time a process spends waiting in the ready queue. It is calculated as:
- Example: If a process has a turnaround time of 10 seconds and a burst time of 5 seconds, its waiting time is 5 seconds.
-
Response Time:
- Definition: The time taken from when a process arrives in the ready queue to the first time it gets the CPU. It is important in interactive systems where the promptness of response is crucial.
- FCFS is simple but can cause long waiting times for short processes.
- SJF is efficient but requires knowing the burst times in advance.
- Round Robin ensures fair CPU allocation but can lead to high average waiting times if the time quantum is not well chosen.
- Pre-emptive Priority Scheduling can prioritize important processes but can cause lower-priority processes to starve.
This project references various resources for understanding CPU scheduling algorithms. Below are the relevant links to YouTube videos and playlists that provide in-depth explanations of different scheduling techniques:
-
Complete Playlist on CPU Scheduling Algorithms:
-
All Time in CPU Scheduling Algorithms:
-
First-Come, First-Served (FCFS) Scheduling:
-
Shortest Job First (SJF) Scheduling:
-
Round Robin (RR) Scheduling:
-
Priority Preemptive Scheduling Algorithm (PPSA):
These resources are useful for understanding the theoretical and practical aspects of CPU scheduling algorithms.