CPU Scheduling
CPU scheduling is the method by which an operating system determines which process gets CPU time when multiple processes are waiting to execute. Efficient scheduling enhances performance, reduces waiting time, and improves overall system responsiveness.
1. Objectives of CPU Scheduling
Maximize CPU Utilization: Ensure the CPU remains active as much as possible.
Minimize Waiting Time: Reduce the time processes spend in the ready queue.
Minimize Response Time: Improve system responsiveness, especially for interactive applications.
Increase Throughput: Maximize the number of completed processes per unit time.
2. Key Scheduling Criteria
CPU Utilization: Ensuring the CPU is always executing tasks.
Throughput: Number of completed processes per time unit.
Turnaround Time: Total time from process submission to completion.
Waiting Time: Time spent in the ready queue before execution.
Response Time: Time between a request and the system’s first response.
3. Types of CPU Scheduling
Scheduling can be preemptive (allowing process interruption) or non-preemptive (a process runs until it voluntarily releases the CPU).
4. Common CPU Scheduling Algorithms
1. First-Come, First-Served (FCFS)
Processes execute in order of arrival.
Non-preemptive.
Simple but prone to long waiting times due to the "convoy effect."
2. Shortest Job Next (SJN) / Shortest Job First (SJF)
Processes with the shortest CPU burst execute first.
Can be preemptive (Shortest Remaining Time First - SRTF) or non-preemptive.
Minimizes waiting time but requires knowledge of burst times.
3. Round Robin (RR)
Each process gets a fixed time slice (quantum) before switching.
Preemptive, ensuring fairness among processes.
Great for time-sharing systems but can cause frequent context switching.
4. Priority Scheduling
Processes execute based on priority levels.
Can be preemptive or non-preemptive.
Risk of starvation (low-priority processes never run), but aging techniques can prevent this.
5. Multilevel Queue Scheduling
Processes are divided into separate queues based on priority or type (e.g., system, interactive, batch).
Each queue has its own scheduling algorithm.
Useful for managing different process types efficiently.
6. Multilevel Feedback Queue (MLFQ)
Similar to multilevel queue scheduling, but processes can move between queues based on behavior.
Dynamically adapts to optimize CPU usage and system responsiveness.
5. Context Switching
The process of switching from one executing process to another.
Requires saving the state of the current process and loading the next process’s state.
Frequent context switching can introduce processing overhead.
Comments
Post a Comment