Presentation is loading. Please wait.

Presentation is loading. Please wait.

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.

Similar presentations


Presentation on theme: "Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling."— Presentation transcript:

1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling

2 5.2 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU. In non-preemptive scheduling, a running task is executed till completion. The preemptive scheduling is prioritized. The highest priority process should always be the process that is currently utilized.

3 5.3 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Dispatcher Dispatcher gives control of the CPU to the process selected by the short-term scheduler; this involves: Dispatch latency – time it takes for the dispatcher to stop one process and start another running

4 5.4 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Scheduling Criteria CPU utilization – keep the CPU as busy as possible Throughput – # of processes that complete their execution per time unit. Waiting time – amount of time a process has been waiting in the ready queue Response time – amount of time it takes from when a request was submitted until the first response is produced.

5 5.5 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Scheduling Algorithm Optimization Criteria Max CPU utilization Max throughput Min waiting time Min response time

6 5.6 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Burst Time: Burst Time is actually time that is required to complete execution of particular task or process.

7 5.7 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition First-Come, First-Served (FCFS) Scheduling ProcessBurst Time P 1 24 P 2 3 P 3 3 Suppose that the processes arrive in the order: P 1, P 2, P 3 The Gantt Chart for the schedule is: Waiting time for P 1 = 0; P 2 = 24; P 3 = 27 Average waiting time: (0 + 24 + 27)/3 = 17 P1P1 P2P2 P3P3 2427300

8 5.8 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition FCFS Scheduling (Cont.) Suppose that the processes arrive in the order: P 2, P 3, P 1 The Gantt chart for the schedule is: Waiting time for P 1 = 6; P 2 = 0 ; P 3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case Convoy effect – all the processes wait for the one big process to get off the CPU. P1P1 P3P3 P2P2 63300

9 5.9 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition FCFS Scheduling (Cont.) None preemptive. The process that requests CPU first is allocated it first. FCFS is not good for time sharing.

10 5.10 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Shortest-Job-First (SJF) Scheduling Shortest job next (SJN), also known as Shortest Job First (SJF) or Shortest Process Next (SPN), is a scheduling policy that selects the waiting process with the smallest execution time to execute next. [1] SJN is a non-preemptive algorithm.scheduling policyprocess [1]preemptive SJF is optimal – gives minimum average waiting time for a given set of processes.

11 5.11 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Example of SJF ProcessArrival TimeBurst Time P 1 0.06 P 2 2.08 P 3 4.07 P 4 5.03 SJF scheduling chart Average waiting time = (3 + 16 + 9 + 0) / 4 = 7 P4P4 P3P3 P1P1 3 16 0 9 P2P2 24

12 5.12 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Priority Scheduling A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer  highest priority) Priority scheduling can be either preemptive or non preemptive A preemptive priority algorithm will preemptive the CPU if the priority of the newly arrival process is higher than the priority of the currently running process. Problem  Starvation – low priority processes may never execute Solution  Aging Aging A technique of gradually increasing the priority of processes that wait in the system for a long time. This is a solution to the problem of indefinite blockage of low-priority processes.

13 5.13 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Example of Priority Scheduling ProcessAarri Burst TimeTPriority P 1 103 P 2 11 P 3 24 P 4 15 P 5 52 Priority scheduling Gantt Chart Average waiting time = 8.2 msec P2P2 P3P3 P5P5 1 18 0 16 P4P4 19 6 P1P1

14 5.14 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Round Robin (RR) Each process gets a small unit of CPU time (time quantum q), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. Timer interrupts every quantum to schedule next process

15 5.15 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Example of RR with Time Quantum = 4 ProcessBurst Time P 1 24 P 2 3 P 3 3 The Gantt chart is: better response P1P1 P2P2 P3P3 P1P1 P1P1 P1P1 P1P1 P1P1 0 47 101418222630

16 5.16 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Time Quantum and Context Switch Time


Download ppt "Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling."

Similar presentations


Ads by Google