Download presentation
Presentation is loading. Please wait.
1
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Processes and Their Scheduling
2
5.2 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Topics for the Day: Processes, Scheduling and Synchronization We will cover: Process Concept Process Scheduling Process Synchronization (with focus on mutual exclusion and semaphores) Some Classic Problems in Concurrency
3
5.3 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Concept An operating system executes a variety of programs: Batch system – jobs Time-shared systems – user programs or tasks Process – a program in execution; process execution must progress in sequential fashion Note: process (active entity) is different from program (passive entity). Several processes may be instances of the same program. A process includes, e.g.: program counter Stack (what do you think this is used for?) data section
4
5.4 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process State A process state describes the current status of its execution. As a process executes, it changes state new: The process is being created running: Instructions are being executed waiting: The process is waiting for some event to occur ready: The process is waiting to be assigned to a process terminated: The process has finished execution How do processes change state and why?
5
5.5 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Diagram of Process State
6
5.6 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Control Block (PCB) Information associated with each process by the OS Process state Program counter CPU registers CPU scheduling information Memory-management information Accounting information I/O status information A snapshot of the process in execution. To be saved at CPU context switches.
7
5.7 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Control Block (PCB): Pictorially
8
5.8 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 CPU Switch From Process to Process
9
5.9 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Where do PCBs of Idle Processes Go? PCBs come in and out of process scheduling queues Remind me: What is a queue? What is a priority queue? Which types of queues are common in an OS?
10
5.10 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Scheduling Queues Job queue – set of all processes in the system Ready queue – set of all processes residing in main memory, ready and waiting to execute Device queues – set of processes waiting for an I/O device Processes migrate among the various queues
11
5.11 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Flow of Processes in the OS
12
5.12 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Overview: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms
13
5.13 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Basic Concepts and Assumptions Fact of Life: Maximum CPU utilization obtained with multiprogramming scheduling! CPU–I/O Burst Cycle Assumption: Process execution consists of a cycle of CPU execution and I/O wait CPU burst distribution
14
5.14 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 CPU Scheduler Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them 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 nonpreemptive All other scheduling is preemptive. (Pretty much the rule today, especially for real-time systems.)
15
5.15 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Typical Scheduling Criteria CPU utilization – keep the CPU as busy as possible Throughput – # of processes that complete their execution per time unit Turnaround time – amount of time to execute a particular process 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 (important for time-sharing environment) Question: Which one do we want to optimize? How? General framework: Combinatorial optimization.
16
5.16 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Optimization Criteria Max CPU utilization Max throughput Min turnaround time Min waiting time (our sample criterion) Min response time Fact of life 1: Selecting an appropriate scheduling algorithm is a major design decision. Often one needs to consider several criteria. Fact of life 2: Proper mathematical analysis and experimental evaluation are needed.
17
5.17 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 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: Average waiting time? Can we do better? Pros and cons? P1P1 P2P2 P3P3 2427300
18
5.18 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Shortest-Job-First (SJF) Scheduling Idea: Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time Two schemes: nonpreemptive – once CPU given to the process it cannot be preempted until completes its CPU burst preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF) SJF is optimal – gives minimum average waiting time for a given set of processes
19
5.19 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 ProcessArrival TimeBurst Time P 1 0.07 P 2 2.04 P 3 4.01 P 4 5.04 SJF (non-preemptive) Average waiting time? What if we used preemptive scheduling? Example of Non-Preemptive SJF P1P1 P3P3 P2P2 73160 P4P4 812
20
5.20 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Example of Preemptive SJF ProcessArrival TimeBurst Time P 1 0.07 P 2 2.04 P 3 4.01 P 4 5.04 SJF (preemptive) Average waiting time? Recall that SJF is optimal. Should we look any further? P1P1 P3P3 P2P2 42 11 0 P4P4 57 P2P2 P1P1 16
21
5.21 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Priority Scheduling A priority number (integer) is associated with each process The CPU is allocated to the ready process with the highest priority (typically, smallest integer highest priority) Preemptive nonpreemptive SJF is a priority scheduling where priority is the predicted next CPU burst time Problem Starvation – low priority processes may never execute (example: LegOS scheduler)LegOS scheduler Solution Aging – as time progresses increase the priority of the process in the ready queue
22
5.22 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Round Robin (RR) Idea: Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. Performance q large FIFO q small q must be large with respect to context switch, otherwise overhead is too high
23
5.23 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Example of RR with Time Quantum = 20 ProcessBurst Time P 1 53 P 2 17 P 3 68 P 4 24 The Gantt chart is: Is avg waiting time good for RR? Typically, higher average turnaround than SJF, but better response P1P1 P2P2 P3P3 P4P4 P1P1 P3P3 P4P4 P1P1 P3P3 P3P3 02037577797117121134154162
24
5.24 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Algorithm Evaluation Deterministic modeling – takes a particular predetermined workload and defines the performance of each algorithm for that workload Queueing models Implementation
25
5.25 Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Algorithm Evaluation Evaluation of CPU schedulers by simulation
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.