CPU Scheduling and Scheduling Algorithms
Introduction
CPU scheduling is the process of determining which process in the ready queue will be
allocated the CPU for execution. The goal is to optimize various performance criteria such as
CPU utilization, throughput, and response time. Effective CPU scheduling ensures efficient
utilization of the CPU and improves system performance.
Scheduling Criteria
Scheduling criteria are used to evaluate the effectiveness of scheduling algorithms. The
main criteria include:
1. 1. **CPU Utilization:** The percentage of time the CPU is busy executing processes.
2. 2. **Throughput:** The number of processes completed per unit time.
3. 3. **Turnaround Time:** The total time taken for a process to complete, from
submission to completion.
4. 4. **Waiting Time:** The total time a process spends in the ready queue waiting for the
CPU.
5. 5. **Response Time:** The time from the submission of a request until the first response
is produced.
6. 6. **Fairness:** Ensures that all processes are treated equally without indefinite delays.
CPU Scheduling Algorithms
1. First-Come, First-Served (FCFS)
FCFS is the simplest scheduling algorithm where the process that arrives first is executed
first. It operates in a non-preemptive manner.
**Advantages:** Simple and easy to implement.
**Disadvantages:** High average waiting time and the convoy effect.
2. Shortest Job Next (SJN)
SJN selects the process with the shortest burst time for execution. It can be either
preemptive or non-preemptive.
**Advantages:** Minimizes average waiting time.
**Disadvantages:** May lead to starvation for longer processes.
3. Priority Scheduling
In priority scheduling, each process is assigned a priority, and the CPU is allocated to the
process with the highest priority.
**Advantages:** Provides importance to critical tasks.
**Disadvantages:** May lead to starvation for lower-priority processes.
4. Round Robin (RR)
RR scheduling allocates the CPU to each process in a cyclic order for a fixed time slice or
quantum. It is a preemptive algorithm.
**Advantages:** Fair and provides good response time.
**Disadvantages:** Performance depends on the time quantum selection.
5. Shortest Remaining Time First (SRTF)
SRTF is the preemptive version of SJN. The process with the shortest remaining burst time
is selected for execution.
**Advantages:** Minimizes average waiting time.
**Disadvantages:** May lead to starvation.
Conclusion
CPU scheduling plays a crucial role in optimizing system performance. Different scheduling
algorithms are suitable for different scenarios, and the choice depends on system
requirements and objectives. Understanding scheduling criteria helps in selecting the right
algorithm to meet performance goals.