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
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.
Types of Scheduling
| Type | Description |
|---|---|
| Long-Term | Selects processes from job pool into memory |
| Short-Term | Chooses process for CPU execution |
| Medium-Term | Handles 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
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
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
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
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
| Algorithm | Type | Advantage | Disadvantage |
|---|---|---|---|
| FCFS | Non-Preemptive | Simple | Long waiting time |
| SJF | Both | Minimum waiting time | Burst time prediction difficult |
| Round Robin | Preemptive | Fair scheduling | High 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.