CPU Scheduling Algorithms
CPU scheduling is a process used by the operating system
to decide which task or program gets to use the CPU at a
particular time. Since many programs can run at the same
time, .the OS needs to manage the CPU’s time so that
every program gets a proper chance to run. The purpose
of CPU Scheduling is to make the system more efficient
and faster.
First-Come, First-Served (FCFS)
Process Execution Algorithm Type Advantages Disadvantages
Processes are executed Non-preemptive: Once a Simple and fair in terms Convoy effect: Long
in the order they arrive. process starts, it runs of arrival order. processes delay shorter
until completion. ones.
Shortest Job First (SJF)
Process Execution Algorithm Type Advantages Disadvantages
The process with the Preemptive or non- Minimizes average Starvation of longer
shortest CPU burst preemptive: Can waiting time for processes; requires burst
executes first. interrupt running processes. time prediction.
processes.
Priority Scheduling
Priority scheduling is a non- Advantages Disadvantages
Process Execution
preemptive algorithm and one of the Processes are executed Allows important tasks to Starvation of low-priority
most common scheduling algorithms based on their priority, execute first, improving processes without aging
in batch systems. Each process is higher priority first. responsiveness. mechanisms.
assigned first arrival time (less arrival
time process first) if two processes
have same arrival time, then compare
to priorities (highest process first).
Also, if two processes have same
priority then compare to process
number (less process number first).
This process is repeated while all
process get executed.
Round Robin (RR)
Process Execution Algorithm Type Advantages Disadvantages
Each process gets a fixed Preemptive: Processes Fair for all processes, High context-switching
time slice in a cyclic are interrupted after preventing starvation. overhead, potentially
order. their time slice. impacting performance.
Gantt chart: Time Slice = 5
Key Takeaways
1 FCFS 2 SJF
Simple but can lead to Optimizes average
long waiting times. waiting time but requires
burst time prediction.
3 Priority Scheduling 4 Round Robin
Prioritizes important tasks Fair and prevents
but can cause starvation. starvation but has high
context-switching
overhead.
Comparison Table
Algorithm Type Advantages Disadvantages
FCFS Non-preemptive Simple, fair Convoy effect
SJF Preemptive/Non-preemptive Minimizes waiting time Starvation, burst time
prediction
Priority Scheduling Preemptive/Non-preemptive Prioritizes important tasks Starvation without aging
Round Robin Preemptive Fair, prevents starvation High context-switching
overhead
Preemptive: The operating system controls the timing of each
task and can interrupt a process to switch to another process.
Non-Preemptive :The scheduling in which a running process
cannot be interrupted by any other process