Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

2 5.2 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms

3 5.3 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Objectives To introduce CPU scheduling, which is the basis for multiprogrammed operating systems To describe various CPU-scheduling algorithms

4 5.4 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Basic Concepts Maximum CPU utilization obtained with multiprogramming CPU–I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait  Process execution begins with a CPU burst…That is followed by an I/O burst, which is followed by another CPU burst, then another I/O burst, and so on.  Eventually, the final CPU burst ends with a system request to terminate execution

5 5.5 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Histogram of CPU-burst Times The curve is generally characterized as exponential or hyper exponential The durations of CPU bursts vary greatly from process to process. There is large number of short CPU bursts and a small number of long CPU bursts. An I/O-bound program >>>> has many short CPU bursts. A CPU-bound program >>>> has a few long CPU bursts

6 5.6 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition CPU Scheduler CPU Scheduler (/ short-term scheduler): Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them The ready queue is not necessarily a first-in, first-out (FIFO) queue. It can be implemented as a FIFO queue, a priority queue, a tree, or an unordered linked list.

7 5.7 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Preemptive Scheduling Preemptive Scheduling: CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state 2. Switches from running to ready state 3. Switches from waiting to ready 4. Terminates Scheduling under 1 and 4 is non-preemptive (/cooperative).  Under non-preemptive scheduling, once the CPU has been allocated to a process, the process keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state Scheduling under 2 and 3 is preemptive

8 5.8 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Dispatcher Dispatcher : is the module gives control of the CPU to the process selected by the short-term scheduler. The dispatcher should be as fast as possible, since it is invoked during every process switch. Dispatch latency – time it takes for the dispatcher to stop one process and start another running

9 5.9 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Scheduling Criteria CPU utilization – keep the CPU as busy as possible (represented as percentage) Throughput – # of processes that complete their execution per time unit (e.g. 10 processes /sec) Turnaround time – amount of time to execute a particular process Turnaround time is the sum of the periods spent waiting to get into memory, waiting in the ready queue, executing on the CPU, and doing I/O. Turnaround time is generally limited by the speed of the output device. Waiting time – amount of time a process has been waiting in the ready queue Waiting time is the sum of the periods spent waiting in the ready queue. Response time – amount of time it takes from when a request was submitted until the first response is produced (for time-sharing environment) It is the time it takes to start responding, not the time it takes to output the response.

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

11 5.11 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition

12 5.12 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Scheduling Algorithms First-Come, First-Served Scheduling Shortest-Job-First Scheduling Priority Scheduling Round-Robin Scheduling

13 5.13 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition First-Come, First-Served (FCFS) Scheduling The simplest CPU-scheduling algorithm Basic methodology: The process that requests the CPU first is allocated the CPU first. The implementation of the FCFS: Using a FIFO queue:  When a process enters the ready queue, its PCB is linked onto the tail of the queue. When the CPU is free, it is allocated to the process at the head of the queue. The running process is then removed from the queue. FCFS algorithm is non-preemptive Gantt chart: is a bar chart that illustrates a particular schedule, including the start and finish times of each of the processes.

14 5.14 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition First-Come, First-Served (FCFS) Scheduling Example(1): Consider the following set of processes that arrive at time 0,with the length of the CPU burst given in milliseconds ProcessBurst Time(ms) 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

15 5.15 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition FCFS Scheduling (Cont.) Example(2): Consider the same previous set of processes arrive at time 0,with the length of the CPU burst in milliseconds ProcessBurst Time(ms) P 1 24 P 2 3 P 3 3 Suppose that the processes arrive in the order: P2, P3, P1 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 example (1) Convoy effect >>> short processes wait for the one big process to get off the CPU. This effect results in lower CPU and device utilization than might be possible if the shorter processes were allowed to go first. P1P1 P3P3 P2P2 63300

16 5.16 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition FCFS Scheduling (Cont.) FCFS Pros. (++): Simplest algorithm FCFS Cons. (--): The average waiting time is generally not minimal and affected by processes’ order. Lower CPU and device utilization because of convoy effect Not suitable for time-shared systems

17 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition End of Chapter 5


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

Similar presentations


Ads by Google