Operating System

CPU Scheduling


CPU Scheduling is the process used by an Operating System to decide which process should use the CPU at a particular time. Since multiple processes compete for CPU resources, scheduling helps in maximizing CPU utilization, improving system performance, and reducing waiting time.

Efficient scheduling ensures that all processes get fair access to the CPU while maintaining responsiveness and system stability.


Objectives of CPU Scheduling

  • Maximize CPU utilization
  • Reduce waiting time
  • Improve turnaround time
  • Increase throughput
  • Provide fairness among processes
  • Improve response time for interactive systems
CPU scheduling is important because the CPU is one of the most expensive and heavily used resources in a computer system.

Scheduling Queues

Processes move through different queues during execution.

  • Job Queue: Contains all processes in the system.
  • Ready Queue: Contains processes waiting for CPU.
  • Device Queue: Contains processes waiting for I/O devices.
Job Queue
Ready Queue
CPU
Device Queue

Types of Scheduling

TypeDescription
Long-TermSelects processes from job pool into memory
Short-TermChooses process for CPU execution
Medium-TermHandles process swapping

Scheduling Criteria

  • CPU Utilization: Keep CPU busy as much as possible.
  • Throughput: Number of completed processes.
  • Turnaround Time: Total time taken to execute process.
  • Waiting Time: Time spent waiting in ready queue.
  • Response Time: Time until first response is produced.

First Come First Serve (FCFS)

FCFS executes processes in the order they arrive. It is the simplest scheduling algorithm.

  • Non-preemptive scheduling algorithm
  • Easy to implement
  • Can cause long waiting times
P1
P2
P3

Shortest Job First (SJF)

SJF selects the process with the shortest burst time first.

  • Provides minimum average waiting time
  • Can be preemptive or non-preemptive
  • Difficult to predict burst time accurately
Example: If processes have burst times 2ms, 5ms, and 8ms, SJF executes the 2ms process first.

Priority Scheduling

In Priority Scheduling, CPU is assigned according to process priority.

  • Higher priority processes execute first
  • Can be preemptive or non-preemptive
  • May cause starvation of low priority processes
P1 - Priority 1
P2 - Priority 2
P3 - Priority 3

Round Robin Scheduling

Round Robin assigns CPU to each process for a fixed time quantum.

  • Preemptive scheduling algorithm
  • Provides fairness among processes
  • Widely used in time-sharing systems
P1
P2
P3

Dispatcher

The dispatcher is responsible for giving control of the CPU to the selected process.

  • Performs context switching
  • Switches CPU to user mode
  • Starts execution of selected process

Comparison of Scheduling Algorithms

AlgorithmTypeAdvantageDisadvantage
FCFSNon-PreemptiveSimpleLong waiting time
SJFBothMinimum waiting timeBurst time prediction difficult
Round RobinPreemptiveFair schedulingHigh context switching

Summary

CPU Scheduling is an essential function of Operating Systems. It determines how processes are allocated CPU time efficiently. Different scheduling algorithms are used depending on system requirements such as fairness, responsiveness, and throughput.

Ready to test your Chapter III: CPU Scheduling knowledge?

Chapter III: CPU Scheduling

A short module quiz for CPU scheduling algorithms, queues, dispatching, and performance criteria.

5 questions·No time limit·Instant feedback