Download Part 1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Processes and Their Scheduling
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
Silberschatz, Galvin and Gagne ©2007
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
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.2
Silberschatz, Galvin and Gagne ©2007
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
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.3
Silberschatz, Galvin and Gagne ©2007
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?
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.4
Silberschatz, Galvin and Gagne ©2007
Diagram of Process State
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.5
Silberschatz, Galvin and Gagne ©2007
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.
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.6
Silberschatz, Galvin and Gagne ©2007
Process Control Block (PCB): Pictorially
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.7
Silberschatz, Galvin and Gagne ©2007
CPU Switch From Process to Process
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.8
Silberschatz, Galvin and Gagne ©2007
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?
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.9
Silberschatz, Galvin and Gagne ©2007
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
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.10
Silberschatz, Galvin and Gagne ©2007
Flow of Processes in the OS
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.11
Silberschatz, Galvin and Gagne ©2007
Overview: CPU Scheduling



Basic Concepts
Scheduling Criteria
Scheduling Algorithms
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.12
Silberschatz, Galvin and Gagne ©2007
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

Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.13
Silberschatz, Galvin and Gagne ©2007
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.)
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.14
Silberschatz, Galvin and Gagne ©2007
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.
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.15
Silberschatz, Galvin and Gagne ©2007
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.
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.16
Silberschatz, Galvin and Gagne ©2007
First-Come, First-Served (FCFS) Scheduling

Process
Burst Time
P1
24
P2
3
P3
3
Suppose that the processes arrive in the order: P1 , P2 , P3
The Gantt Chart for the schedule is:
P1
P2
0



24
P3
27
30
Average waiting time?
Can we do better?
Pros and cons?
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.17
Silberschatz, Galvin and Gagne ©2007
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
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.18
Silberschatz, Galvin and Gagne ©2007
Example of Non-Preemptive SJF
Process

Arrival Time
Burst Time
0.0
2.0
4.0
5.0
7
4
1
4
P1
P2
P3
P4
SJF (non-preemptive)
P1
0


3
P3
7
P2
8
P4
12
16
Average waiting time?
What if we used preemptive scheduling?
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.19
Silberschatz, Galvin and Gagne ©2007
Example of Preemptive SJF

Process
P1
P2
P3
P4
SJF (preemptive)
P1
0


P2
2
Arrival Time
0.0
2.0
4.0
5.0
P3
4
P2
5
Burst Time
7
4
1
4
P4
7
P1
11
16
Average waiting time?
Recall that SJF is optimal. Should we look any further?
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.20
Silberschatz, Galvin and Gagne ©2007
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)
Solution  Aging – as time progresses increase the priority
of the process in the ready queue
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.21
Silberschatz, Galvin and Gagne ©2007
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
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.22
Silberschatz, Galvin and Gagne ©2007
Example of RR with Time Quantum = 20

Process
P1
P2
P3
P4
The Gantt chart is:
P1
0

P2
20
37
P3
Burst Time
53
17
68
24
P4
57
P1
77
P3
97 117
P4
P1
P3
P3
121 134 154 162
Is avg waiting time good for RR?
Typically, higher average turnaround than SJF, but better
response
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.23
Silberschatz, Galvin and Gagne ©2007
Algorithm Evaluation



Deterministic modeling – takes a particular
predetermined workload and defines the
performance of each algorithm for that
workload
Queueing models
Implementation
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.24
Silberschatz, Galvin and Gagne ©2007
Algorithm Evaluation
Evaluation of CPU schedulers by simulation
Operating System Concepts with Java – 7th Edition, Nov 15, 2006
5.25
Silberschatz, Galvin and Gagne ©2007
Related documents