CPU Scheduling Algorithms in OS: FCFS, SJF, SRTF, Priority & Round Robin
When many processes are waiting in the ready queue, the operating system must decide which process should get the CPU next. Different rules can be used to make this decision. These rules are called CPU Scheduling Algorithms in OS.
Students usually know the names FCFS, SJF, SRTF, Priority Scheduling and Round Robin, but numerical questions become confusing when arrival time, burst time, preemption, priority, time quantum and Gantt charts appear together. In this chapter, we will solve every major CPU scheduling algorithm step by step.
What Are CPU Scheduling Algorithms in Operating System?
A CPU scheduling algorithm is a rule used by the operating system to choose one process from the ready queue for CPU execution.
Different algorithms use different information. One algorithm may look at arrival time. Another may look at CPU burst time. Another may use priority. Round Robin gives processes repeated turns.
CPU Scheduling Algorithms in OS are methods used to decide which ready process should execute next and for how long.
Why Do We Need Different CPU Scheduling Algorithms?
Preemptive vs Non-Preemptive CPU Scheduling
Before learning the algorithms, understand one very important difference.
Once a process gets CPU, it normally continues until its current CPU burst finishes or it blocks.
The operating system can interrupt a running process and give the CPU to another ready process.
FCFS → Non-preemptive
SJF → Usually taught as non-preemptive
SRTF → Preemptive
Priority → Can be preemptive or non-preemptive
Round Robin → Preemptive
Terms You Must Know Before Solving CPU Scheduling Numericals
What Is a Gantt Chart in CPU Scheduling?
A Gantt chart in CPU scheduling is a timeline showing which process uses the CPU during each time interval.
Once the Gantt chart is correct, completion time, turnaround time, waiting time and response time become much easier to calculate.
Process Set Used in Our Solved Examples
To make comparison easy, we will use the same four processes for all major CPU Scheduling Algorithms in OS.
FCFS Scheduling Algorithm in OS
First Come First Served
FCFS Scheduling is the simplest CPU scheduling algorithm. The process that arrives first gets the CPU first.
It follows the same basic idea as a normal queue: first arrival → first service.
Is FCFS Preemptive or Non-Preemptive?
FCFS is a non-preemptive CPU scheduling algorithm.
Once a process starts its CPU burst, another newly arriving process does not normally remove it from the CPU.
How FCFS Scheduling Works
FCFS Solved Example
Arrival order is: P1 → P2 → P3 → P4.
| Process | AT | BT | CT | TAT | WT | RT |
|---|---|---|---|---|---|---|
| P1 | 0 | 7 | 7 | 7 | 0 | 0 |
| P2 | 2 | 4 | 11 | 9 | 5 | 5 |
| P3 | 4 | 1 | 12 | 8 | 7 | 7 |
| P4 | 5 | 4 | 16 | 11 | 7 | 7 |
Convoy Effect in FCFS Scheduling
FCFS can suffer from the convoy effect.
This happens when a long CPU-bound process reaches the front of the queue and several short processes are forced to wait behind it.
P1
Advantages of FCFS
- very simple to understand
- easy to implement using a queue
- processes are served in arrival order
- does not normally starve an arrived process
Disadvantages of FCFS
- short processes may wait behind long processes
- can produce high average waiting time
- can suffer from convoy effect
- not ideal when fast interactive response is important
SJF Scheduling Algorithm in OS
Shortest Job First
SJF Scheduling selects the ready process with the shortest CPU burst time.
At every scheduling decision, choose the available process with the smallest CPU burst.
Is SJF Preemptive or Non-Preemptive?
The standard SJF algorithm is usually taught as non-preemptive.
Once a selected process starts running, a newly arriving shorter process does not interrupt it.
How SJF Scheduling Works
SJF Solved Example
At time 0, only P1 has arrived, so P1 must run first.
P1 completes at time 7. By then P2, P3 and P4 are ready.
✓ shortest
So P3 runs next. After P3, P2 and P4 both have burst time 4. Using arrival time as the tie breaker, P2 goes before P4.
| Process | AT | BT | CT | TAT | WT | RT |
|---|---|---|---|---|---|---|
| P1 | 0 | 7 | 7 | 7 | 0 | 0 |
| P2 | 2 | 4 | 12 | 10 | 6 | 6 |
| P3 | 4 | 1 | 8 | 4 | 3 | 3 |
| P4 | 5 | 4 | 16 | 11 | 7 | 7 |
Why Is SJF Important?
When the next CPU burst lengths are known accurately, choosing shorter work first can reduce average waiting time.
The practical problem is that the operating system normally does not know the exact future CPU burst of a process.
CPU Burst Prediction in SJF
In theory and textbooks, previous CPU bursts can be used to estimate a future burst. One common prediction formula is:
τn+1 = αtn + (1 − α)τn
where:
tn = actual previous burst
τn = previous prediction
α = weight between 0 and 1
Advantages of SJF
- can reduce average waiting time
- short jobs finish quickly
- useful concept for understanding burst-based scheduling
Disadvantages of SJF
- future CPU burst is not normally known exactly
- long processes may wait for a long time
- can suffer from starvation
SRTF Scheduling Algorithm in OS
Shortest Remaining Time First
SRTF Scheduling is the preemptive version of Shortest Job First.
The CPU is given to the ready process having the smallest remaining execution time.
Difference Between SJF and SRTF
Looks at shortest burst when CPU becomes free.
Normally non-preemptive.
Continuously considers remaining time as processes arrive.
Preemptive.
SRTF Solved Example Step by Step
| Process | AT | BT | CT | TAT | WT | RT |
|---|---|---|---|---|---|---|
| P1 | 0 | 7 | 16 | 16 | 9 | 0 |
| P2 | 2 | 4 | 7 | 5 | 1 | 0 |
| P3 | 4 | 1 | 5 | 1 | 0 | 0 |
| P4 | 5 | 4 | 11 | 6 | 2 | 2 |
Advantages of SRTF
- short processes can receive CPU quickly
- can reduce average waiting time
- responds to newly arriving short jobs
Disadvantages of SRTF
- requires burst-time estimation
- long processes may starve
- preemption causes extra context-switch overhead
- more complex than FCFS
Priority Scheduling Algorithm in OS
CPU selection based on process priority
In Priority Scheduling, every process is assigned a priority. The process with the highest scheduling priority is selected first.
In our example: smaller priority number = higher priority.
Types of Priority Scheduling
Priority Scheduling can be:
Once a process starts, it continues its current CPU burst.
A newly arrived higher-priority process may interrupt the running process.
Non-Preemptive Priority Solved Example
At time 0 only P1 exists, so P1 starts. At time 7, all remaining processes are available.
Their priorities are: P2 = 1, P4 = 2, P3 = 4. Therefore the order becomes: P2 → P4 → P3.
| Process | Priority | CT | TAT | WT | RT |
|---|---|---|---|---|---|
| P1 | 3 | 7 | 7 | 0 | 0 |
| P2 | 1 | 11 | 9 | 5 | 5 |
| P3 | 4 | 16 | 12 | 11 | 11 |
| P4 | 2 | 15 | 10 | 6 | 6 |
Preemptive Priority Example
Now suppose the same priority values are used with preemptive Priority Scheduling.
P1 starts at time 0. At time 2, P2 arrives with priority 1, which is higher than P1's priority 3. P2 therefore preempts P1.
Starvation in Priority Scheduling
A low-priority process may keep waiting if higher-priority processes continue to enter the ready queue.
This problem is called starvation.
Problem: Starvation
A low-priority process may wait for a very long time.
Solution: Aging
Gradually improve the priority of a process that has waited for a long time.
Advantages of Priority Scheduling
- important processes can receive preference
- flexible scheduling policy
- can be implemented as preemptive or non-preemptive
Disadvantages of Priority Scheduling
- low-priority processes may starve
- priority assignment can be difficult
- aging may be required to maintain fairness
Round Robin Scheduling Algorithm in OS
Time-sharing CPU scheduling
Round Robin Scheduling is a preemptive CPU scheduling algorithm commonly associated with time-sharing systems.
Every ready process receives a small fixed amount of CPU time called a time quantum or time slice.
Time Quantum = 2
Each process can use the CPU for at most 2 time units during one turn.
If the process still has remaining burst time, it goes back to the ready queue.
How Round Robin Scheduling Works
Round Robin Solved Example
We will use: Time Quantum = 2 units.
| Process | AT | BT | CT | TAT | WT | RT |
|---|---|---|---|---|---|---|
| P1 | 0 | 7 | 16 | 16 | 9 | 0 |
| P2 | 2 | 4 | 9 | 7 | 3 | 0 |
| P3 | 4 | 1 | 7 | 3 | 2 | 2 |
| P4 | 5 | 4 | 15 | 10 | 6 | 4 |
Why Response Time Is Important in Round Robin
Round Robin gives processes repeated chances to use the CPU.
Because a process does not need to wait for every earlier process to fully finish, it can often receive its first CPU service sooner than in a simple FCFS queue.
Effect of Time Quantum in Round Robin
If the quantum becomes very large, Round Robin begins to behave more like FCFS because processes may finish before their time slice expires.
Processes get frequent turns, but the number of context switches can increase, creating more scheduling overhead.
Advantages of Round Robin
- gives ready processes repeated CPU opportunities
- useful for interactive and time-sharing ideas
- can provide good response time
- simple queue-based operation
Disadvantages of Round Robin
- performance depends strongly on time quantum
- small quantum creates more context switches
- average waiting time may not be minimum
FCFS vs SJF vs SRTF vs Priority vs Round Robin
| Algorithm | Main Selection Rule | Preemptive? | Main Strength | Main Problem |
|---|---|---|---|---|
| FCFS | Earliest arrival | No | Very simple | Convoy effect |
| SJF | Shortest CPU burst | No | Low average waiting can be achieved with accurate burst knowledge | Need burst prediction; starvation possible |
| SRTF | Shortest remaining time | Yes | Quick service for short remaining work | Starvation and preemption overhead |
| Priority | Highest scheduling priority | Both possible | Important jobs can get preference | Starvation |
| Round Robin | Fixed time quantum in turns | Yes | Responsive and fair-turn behaviour | Quantum and context-switch overhead |
Performance Comparison Using Our Same Process Set
Because every algorithm above used the same processes, we can directly compare the calculated averages.
| Algorithm | Average Turnaround | Average Waiting | Average Response |
|---|---|---|---|
| FCFS | 8.75 | 4.75 | 4.75 |
| SJF | 8.00 | 4.00 | 4.00 |
| SRTF | 7.00 | 3.00 | 0.50 |
| Priority – Non-Preemptive | 9.50 | 5.50 | 5.50 |
| Priority – Preemptive | 9.00 | 5.00 | 3.00 |
| Round Robin – q = 2 | 9.00 | 5.00 | 1.50 |
Change the arrival times, burst times, priorities or Round Robin time quantum, and the result can change completely.
How Different CPU Scheduling Algorithms Think
Which CPU Scheduling Algorithm Is Best?
There is no single CPU scheduling algorithm that is best for every workload.
The answer depends on what the system is trying to improve.
What Happens When Two Processes Have the Same Burst Time or Priority?
CPU scheduling questions often contain ties.
For example, two SJF processes may have the same burst time, or two Priority Scheduling processes may have the same priority.
If arrival time is also equal, the question may use process order or another defined rule.
Always write the tie-breaking assumption before solving an ambiguous question.
What If No Process Has Arrived?
Sometimes the CPU becomes free but no process has arrived yet.
In that case, the CPU remains idle until the next process becomes ready.
Do not skip idle time in the Gantt chart. It affects completion and turnaround calculations.
Waiting Time vs Response Time
This is one of the most common mistakes in CPU scheduling numericals.
Measures only the wait before the process gets CPU for the first time.
Measures all time spent waiting in the ready queue during the process's life.
In algorithms such as SRTF and Round Robin, a process can run, get preempted and wait again. Therefore its total waiting time can be much larger than its response time.
Context Switching in CPU Scheduling Algorithms
In preemptive algorithms, the CPU may move from one process to another many times.
During a context switch, the operating system saves the state of the old process and restores the state of the new process.
Context switching allows multitasking, but it also creates overhead.
Which CPU Scheduling Algorithms Can Cause Starvation?
Starvation means a process remains ready but waits for an excessively long time because other processes keep receiving CPU preference.
How to Solve Any CPU Scheduling Numerical Step by Step
Note PID, Arrival Time, Burst Time, Priority and Time Quantum if required.
FCFS, SJF, SRTF, Priority or Round Robin.
This changes whether a running process can be interrupted.
Never calculate final averages before the timeline is correct.
Record when every process finishes.
TAT = CT − AT.
WT = TAT − BT.
RT = first CPU start − arrival time.
Add individual values and divide by the number of processes.
Common Mistakes in CPU Scheduling Algorithms
SJF, SRTF and Priority Scheduling can only choose among processes currently ready.
SRTF compares remaining CPU time.
Follow the convention given in the question.
After its quantum ends, it goes back to the ready queue if CPU work remains.
Response time only measures time until first CPU service.
If no process is ready, show IDLE in the Gantt chart.
Decide the tie rule once and use it consistently.
SRTF is the preemptive version and can interrupt a running process.
Easy Memory Trick for CPU Scheduling Algorithms
CPU Scheduling Algorithms Exam Preparation
For a 2-Mark Question
Answer: CPU Scheduling Algorithms in OS are methods used by the operating system to select which ready process gets the CPU. Common algorithms include FCFS, SJF, SRTF, Priority Scheduling and Round Robin.
For a 5-Mark Question
Explain:
- meaning of CPU scheduling algorithm
- FCFS
- SJF or SRTF
- Priority Scheduling
- Round Robin
- one major advantage or limitation of each
For a 10-Mark Question
Write in this order:
- CPU scheduling definition
- preemptive vs non-preemptive scheduling
- AT, BT, CT, TAT, WT and RT
- Gantt chart concept
- FCFS with example
- SJF with example
- SRTF with example
- Priority Scheduling with starvation and aging
- Round Robin with time quantum
- comparison of algorithms
For a Numerical Question
Golden rule: First make the correct Gantt chart. Then calculate CT → TAT → WT → RT → averages.
CPU Scheduling Algorithms Practice Questions
CPU Scheduling Algorithms Quick Revision
Frequently Asked Questions About CPU Scheduling Algorithms in OS
What are CPU Scheduling Algorithms in OS?
CPU Scheduling Algorithms in OS are methods used by the operating system to select which ready process should receive the CPU.
What are the main CPU scheduling algorithms?
Common CPU scheduling algorithms include FCFS, SJF, SRTF, Priority Scheduling and Round Robin.
What is FCFS Scheduling?
FCFS or First Come First Served executes processes according to their arrival order and is normally non-preemptive.
What is convoy effect in FCFS?
Convoy effect occurs when short processes wait behind a long process that is already ahead of them in the FCFS queue.
What is SJF Scheduling?
Shortest Job First selects the ready process with the smallest CPU burst. The standard form is non-preemptive.
What is SRTF Scheduling?
Shortest Remaining Time First is the preemptive version of SJF. It selects the ready process with the smallest remaining CPU execution time.
What is the difference between SJF and SRTF?
SJF normally allows the selected process to complete its current CPU burst, while SRTF may preempt it if a process with a shorter remaining time becomes ready.
What is Priority Scheduling?
Priority Scheduling selects processes according to scheduling priority. It can be implemented in preemptive or non-preemptive form.
What is starvation in CPU scheduling?
Starvation occurs when a process waits for an excessively long time because other processes repeatedly receive scheduling preference.
What is aging in CPU scheduling?
Aging gradually improves the priority of a process that has been waiting for a long time and can help reduce starvation.
What is Round Robin Scheduling?
Round Robin is a preemptive scheduling algorithm in which ready processes receive CPU time in repeated turns using a fixed time quantum.
What is time quantum in Round Robin?
Time quantum is the maximum CPU time normally given to a process during one Round Robin turn before it may be preempted and returned to the ready queue.
What happens if Round Robin time quantum is too large?
If the time quantum becomes very large compared with process burst times, Round Robin begins to behave more like FCFS.
What happens if Round Robin time quantum is too small?
A very small time quantum may increase the number of context switches and therefore increase scheduling overhead.
How is turnaround time calculated?
Turnaround Time is calculated as Completion Time minus Arrival Time.
How is waiting time calculated?
In standard CPU scheduling numericals, Waiting Time is calculated as Turnaround Time minus Burst Time.
How is response time calculated?
Response Time is calculated as the time of first CPU allocation minus the process Arrival Time.
Which CPU scheduling algorithm is best?
No single scheduling algorithm is best for every workload. The suitable policy depends on goals such as waiting time, response, fairness, throughput and scheduling overhead.
Conclusion
CPU Scheduling Algorithms in OS become much easier when you stop memorising names and instead understand the question each algorithm asks.
FCFS Scheduling asks who arrived first. SJF Scheduling looks for the shortest available CPU burst. SRTF Scheduling keeps checking the shortest remaining execution time. Priority Scheduling uses process priority, while Round Robin Scheduling gives ready processes repeated turns using a fixed time quantum.
For numerical questions, always build the Gantt chart first. Then calculate Completion Time, Turnaround Time, Waiting Time and Response Time.
Once FCFS, SJF, SRTF, Priority and Round Robin are clear, advanced scheduling topics such as Multilevel Queue and Multilevel Feedback Queue become much easier to understand.
