CS330 - Operating Systems
Scheduling Algorithms, Performance Metrics, and Analysis
CPU scheduling is the basis of multiprogrammed operating systems. By switching the CPU among processes, the OS can make the computer more productive.
Process execution consists of a cycle of CPU execution and I/O wait:
Process execution begins with a CPU burst, followed by an I/O burst, then another CPU burst, and so on.
The CPU scheduler selects from among the processes in the ready queue and allocates a CPU core to one of them.
The dispatcher gives control of the CPU to the process selected by the scheduler. This involves:
Dispatch latency: Time it takes for the dispatcher to stop one process and start another running.
Keep the CPU as busy as possible. In real systems, should range from 40% (light load) to 90% (heavy load).
Number of processes that complete execution per time unit. Higher is better.
Amount of time to execute a particular process. Sum of periods spent waiting, ready queue, executing, and doing I/O.
Amount of time a process has been waiting in the ready queue.
Time from submission of request until first response is produced. Important for interactive systems.
| Criterion | Optimization Goal |
|---|---|
| CPU Utilization | Maximize |
| Throughput | Maximize |
| Turnaround Time | Minimize |
| Waiting Time | Minimize |
| Response Time | Minimize |
CPU scheduling decisions may take place when a process:
Virtually all modern operating systems including Windows, macOS, Linux, and UNIX use preemptive scheduling algorithms.
| Process | Burst Time |
|---|---|
| P1 | 24 |
| P2 | 3 |
| P3 | 3 |
Arrival Order: P1, P2, P3
| Process | Waiting Time | Turnaround Time |
|---|---|---|
| P1 | 0 | 24 |
| P2 | 24 | 27 |
| P3 | 27 | 30 |
| Average | 17 | 27 |
Short processes behind long process. All other processes wait for one big process to get off CPU. This effect results in lower CPU and device utilization.
If arrival order changes to P2, P3, P1:
Once CPU given to process, it cannot be preempted until completes its CPU burst
If new process arrives with CPU burst length less than remaining time of current process, preempt. Also known as Shortest-Remaining-Time-First
| Process | Arrival Time | Burst Time |
|---|---|---|
| P1 | 0 | 8 |
| P2 | 1 | 4 |
| P3 | 2 | 9 |
| P4 | 3 | 5 |
Average waiting time = [(10-1) + (1-1) + (17-2) + (5-3)] / 4 = 26/4 = 6.5
| Process | Burst Time | Priority |
|---|---|---|
| P1 | 10 | 3 |
| P2 | 1 | 1 |
| P3 | 2 | 4 |
| P4 | 1 | 5 |
| P5 | 5 | 2 |
Low priority processes may never execute.
As time progresses, increase the priority of the process.
| Process | Burst Time |
|---|---|
| P1 | 24 |
| P2 | 3 |
| P3 | 3 |
| Process | Waiting Time | Turnaround Time |
|---|---|---|
| P1 | 6 | 30 |
| P2 | 4 | 7 |
| P3 | 7 | 10 |
| Average | 5.66 | 15.66 |
Ready queue is partitioned into separate queues based on process characteristics.
Allows process to move between queues. The idea is to separate processes according to characteristics of their CPU bursts.
| Algorithm | Preemptive | Advantages | Disadvantages | Best For |
|---|---|---|---|---|
| FCFS | No | Simple, Fair | Convoy effect, Poor waiting time | Batch systems |
| SJF | Both | Optimal average waiting time | Starvation, Need to know burst time | When burst times known |
| Priority | Both | Important jobs first | Starvation | Real-time systems |
| Round Robin | Yes | Good response time, Fair | Higher turnaround time | Time-sharing systems |
Consider the following set of processes with arrival time 0:
| Process | Burst Time | Priority |
|---|---|---|
| P1 | 2 | 2 |
| P2 | 1 | 1 |
| P3 | 8 | 4 |
| P4 | 4 | 2 |
| P5 | 5 | 3 |
Order: P2 → P1 → P4 → P5 → P3
| Process | Waiting Time | Turnaround Time |
|---|---|---|
| P1 | 1 | 3 |
| P2 | 0 | 1 |
| P3 | 12 | 20 |
| P4 | 3 | 7 |
| P5 | 7 | 12 |
Order: P1(2) → P2(1) → P3(2) → P4(2) → P5(2) → P3(2) → P4(2) → P5(2) → P3(2) → P5(1) → P3(2)
| Process | Waiting Time | Turnaround Time |
|---|---|---|
| P1 | 0 | 2 |
| P2 | 2 | 3 |
| P3 | 12 | 20 |
| P4 | 9 | 13 |
| P5 | 13 | 18 |
Order: P2 → P1 → P4 → P5 → P3
| Process | Waiting Time | Turnaround Time |
|---|---|---|
| P1 | 1 | 3 |
| P2 | 0 | 1 |
| P3 | 12 | 20 |
| P4 | 3 | 7 |
| P5 | 7 | 12 |
Q1. Which scheduling algorithm is non-preemptive?
Q2. Which scheduling algorithm gives the best average response time?
Q3. If time quantum is too small in RR scheduling:
Q4. Which problem is associated with Priority Scheduling?
Q5. SJF scheduling is optimal because it gives:
Q6. Define turnaround time and throughput. (3 marks)
Q7. What is the convoy effect in FCFS scheduling? (2 marks)
Convoy effect occurs when short processes get stuck behind a long process. All other processes wait for one big process to release the CPU, resulting in lower CPU and device utilization.
Q8. How does aging solve the starvation problem in Priority Scheduling? (2 marks)
Aging gradually increases the priority of processes that wait in the system for a long time. This ensures that even low-priority processes will eventually get high enough priority to be executed.
| Term | Definition |
|---|---|
| CPU Burst | Time process spends being executed in CPU |
| I/O Burst | Time process spends waiting for I/O operation |
| CPU Scheduler | Selects process from ready queue for execution |
| Dispatcher | Gives control of CPU to selected process |
| Dispatch Latency | Time to stop one process and start another |
| Preemptive | Process can be interrupted during execution |
| Non-preemptive | Process runs until completion or I/O |
| Time Quantum | Time slice in Round Robin scheduling |
| Convoy Effect | Short processes waiting behind long process |
| Starvation | Process never gets CPU time |
| Aging | Increasing priority over time |
| Gantt Chart | Visual representation of process scheduling |
[Insert diagram showing alternating CPU and I/O bursts]
[Insert dispatcher switching diagram from slides]
[Insert multilevel queue diagram]
Note: Please provide the actual diagrams from your Chapter_5.pdf slides to replace these placeholders.