OS Week 7 CPU Scheduling
OS Week 7 CPU Scheduling
Operating
systems
CPU Scheduling
•CPU scheduling is a crucial feature of operating systems.
Switching context
Jumping to the proper location in the user program to restart that program
Dispatch latency – time it takes for the dispatcher to stop one process and
•Involves storing CPU registers, program counter, and other process attributes.
•Adds overhead to the system, as no useful work is done during the switch.
execution.
•The operating system can forcibly take the CPU away from a running process.
execute sooner.
Burst Time : The CPU time required for a process to complete execution.
Waiting Time: Time a process spends in the ready queue before execution.
2.Execution: The CPU takes the first process from the front of
the queue, executes it until it is complete, and then removes it
from the queue.
3.Repeat: The CPU takes the next process in the queue and
repeats the execution process.
FCFS : Processes with Same Arrival Time
FCFS: Processes with Same Arrival Time
FCFS: Processes with Same Arrival Time
FCFS: Processes with Same Arrival Time
FCFS: Processes with Same Arrival Time
FCFS: Calculation
FCFS Scenario 2: Different Arrival times
FCFS Scenario 2: Different Arrival times
FCFS Scenario 2: Different Arrival times
FCFS Scenario 2: Different Arrival times
FCFS Scenario 2: Different Arrival times
Shortest Job First
•Step 1: Sort by Arrival Time
•First, consider only the processes that have arrived so far
(i.e., those available in the ready queue).
•Among these, select the process with the shortest burst time
(not necessarily the one with the earliest arrival time).
A simple and fundamental CPU scheduling Being non-preemptive, it can lead to long
algorithm. waiting times if a long process arrives first
Executes processes in arrival order, (convoy effect).
ensuring fairness. Results in higher average waiting time
Easy to implement without complex data compared to other scheduling algorithms.
structures. Short processes may experience delays if
Prevents starvation as every process they follow longer ones, reducing efficiency.
gets executed. Processes at the end of the queue wait
Suitable for batch systems where longer longer to execute.
execution times are acceptable. Unsuitable for time-sharing systems, as it
doesn't ensure equal CPU time distribution.
Shortest Job First
•Step 1: Sort by Arrival Time
•First, consider only the processes that have arrived so far
(i.e., those available in the ready queue).
•Among these, select the process with the shortest burst time
(not necessarily the one with the earliest arrival time).
SJF is better than the First come first serve SJF may cause very long turn-around times
(FCFS) algorithm as it reduces the average or starvation.
waiting time. In SJF job completion time must be known
SJF is generally used for long term earlier.
scheduling. Many times it becomes complicated to
It is suitable for the jobs running in batches, predict the length of the upcoming CPU
where run times are already known. request.
SJF is probably optimal in terms of average
Turn Around Time (TAT).
Shortest Remaining time first
• Execution: The process uses the CPU for the allocated time.
Fairness: Each process gets an equal share Overhead: Switching between processes can
Responsiveness: Round Robin can handle can cause the CPU to feel unresponsive as it
multiple processes without significant delays, waits for a process to finish its time.
https://www.baeldung.com/cs/cpu-scheduling
https://www.geeksforgeeks.org/cpu-scheduling-in-operating-systems/