Upload
007wasr
View
224
Download
0
Embed Size (px)
Citation preview
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 1/30
ntroduction to Operating Systems
Lecture
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 2/30
Lecture 2 contentsProcess in the hardware.Process States and control blockProcess SchedulingScheduling: Behavior and Algorithms
2
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 3/30
Running process in the
hardware components.
3
Hard Disk :programs are
saved
Slowmechanical device
Main Memory :Processes areloaded in thememory and
ready/waitingfor execution
Running program
Fasterelectronicdevice
Processor :Run instruction by
instruction
Registry : Load a singleinstruction for a singlerunning process
Manages the allocation ofprocesses in the memory
Controls which process torun now in the processor
Cash Memory :Instructions aresaved to increasethe processing
Temporary memory , nearer to
the processor and faster than themain memory.
selected process
Operating System :
Fastest Memoryin the processor
Interrupt
Terminatingrunning process
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 4/30
Process states
4
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 5/30
5
PROCESS CONTROL BLOCK: is a block of data, loaded withthe process in the memory, that contains informationassociated with each process.
It's a data structure holding:
PC, CPU registers,
memory management information,
accounting ( time used, ID, ... )
I/O status ( such as file resources ),
scheduling data ( relative priority, etc. )Process State (so running, ready, etc. is simply a field inthe PCB ).
Process control block
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 6/30
3: Processes 6
The act of Scheduling a process means changing the active PCB pointed to by theCPU.
When CPU switches to another process, the system must save the state of the oldprocess into the memory and load the saved state for the new process from thememory via a context switch.
The CPU switchingfrom one process toanother.
Process Scheduling: Switching
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 7/30
7
Ready Q And IO Q’s
(Process is driven by events that are triggered by needs and availability )
Ready queue = contains those processes that are ready to run.
I/O queue (waiting state ) = holds those processes waiting for I/O service.
Process Scheduling: Queues
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 8/30
In many multitasking systems the processor scheduling subsystemoperates on three levels
Long term scheduling : which determines which programs areadmitted to the system for execution and when, and which onesshould be exited. selects which processes should be brought intothe ready queueShort term scheduling (or dispatching) : which determines whichof the ready processes can have CPU resources, and for how long.
selects which process should be executed next
3: Processes 8
Process Scheduling :
(short/long term scheduling)
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 9/30
Interrupt Handler
ShortTerm
Scheduler
ShortTermScheduler
Long TermScheduler
Long TermScheduler
Process Scheduling :(short/long term scheduling)
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 10/30
Scheduling : definitionInterleave the execution of processes to maximize CPUutilization while providing reasonable response time
The scheduler determines:o Who will runo When it will run
o For how long
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 11/30
Process Scheduling Interleave the execution of processes to maximize CPU utilizationwhile providing reasonable response time.
Fairness : Comparable processes should get comparable service
Efficiency: keep CPU and I/O devices busyResponse time : minimize, for interactive users
Turnaround time: average time for a job to complete
Waiting time: minimize the average over processes
Throughput: number of completed jobs per time unit
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 12/30
Types of Scheduling Non-preemptive scheduling, a process runs until it terminates .Preemptive scheduling, even if the current process is still running,a context switch will occur when its time slice is used up .
Bur st time is an assumption of how long a process requires the CPU between I/O waits. It can not be predicted exactly, before a processstarts.
It means the amount of time a process uses the CPU for a single time.(A process can use the CPU several times before complete the job inthe Preemptive schedul ing )
Process Schedulinga context switch is the process of storing andrestoring the state (context) of a process so thatexecution can be resumed from the same point ata later time.
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 13/30
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 14/30
14
Bursts of CPU usage alternate with periods of I/O waito CPU-bound processeso I/O bound processes
Scheduling : behavior types
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 15/30
Scheduling CriteriaCPU utilization – keep the CPU as busy as possible
Throughput – # of processes that complete theirexecution per time unit
Turnaround time – amount of time to execute a particularprocess
Waiting time – amount of time a process has beenwaiting in the ready queue
Response time – amount of time it takes from when arequest was submitted until the first response isproduced, not output (for time-sharing environment)
15
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 16/30
Scheduling: Algorithms1. FCFS : First-come-first-served (Non-Preempt)
2. SJF: Shortest job first (Non-Preempt)
3. SRTF: Shortest Remaining Time First (Preempt)4. RR : Round robin (Preempt)
5. Priority, Multilevel feedback queues (Preempt)
16
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 17/30
Process Burst time (milli)
P1
P2
P3
24
3
3
If they arrive in the order P1, P2, P3, we get:
0 24 27 30
P1 P2 P3
Average waiting time: (0+24+27) / 3 = 17
Scheduling : 1. FCFS Algorithm FCFS may cause long waiting times
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 18/30
Process Burst time (milli)
P1
P2P3
24
33
If they arrive in the order P1, P2, P3, average waiting time 17
What if they arrive in the order P2, P3, P1?
0 3 30
P1P2 P3
Average waiting time:
6
(0+3+6) / 3 = 3
FCFS may cause long waiting times (cont’d) Scheduling : 1. FCFS Algorithm
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 19/30
19
The CPU is assigned to the process that has the smallest next CPUburstIn some cases, this quantity is known or can be approximated
Process Burst time (milli)
ABC
524
D 1
CB
0 5
A Average waiting time: 5.75
7
D
11 12
D AB
0 1
Average waiting time: 2.75 7
C
12
SJF schedule
3
FCFS schedule
Schedu ling : 2. SJF Algorithm
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 20/30
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 21/30
21
Process Arrival timeP1P2P3
024
P4 5
P10
Preemptive SJF schedule
Burst time7415
2
P2
4
P3
7
P4
11 16
P1
Average waiting time: (9+1+0+2) / 4 = 3
P1(5) P2(2)
5
P2
P4(4)
Schedu ling : 3. SRTF Algorithm
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 22/30
Each process gets a small unit of CPU time ( time-quantum ),usually 10-100 milliseconds
Context switch overhead Time-quantum ~ switching time (or smaller)
Fast response : relatively large waste of CPU time
Time-quantum >> switching timelong response (waiting) times, FCFS
Scheduling : 4. Round Robin
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 23/30
23
Context switch overheadContext Switching is time consuming
Choosing a long time quantum to avoid switching:o Deteriorates response time.
o Increases CPU utilization
Choosing a short time quantum:o Faster response
o CPU wasted on switches
Scheduling : 4. Round Robin
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 24/30
24
Scheduling : 4. Round Robin
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 25/30
Select runnable process with highest priority
When there are classes of processes with the samepriority:
o group prioritieso each priority group may uses round robin
schedulingo A process from a lower priority group runs only
if there is no higher priority process waiting
Scheduling : 5. Priority Alg.
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 26/30
26
Multi-Level Queue SchedulingHighest priority
system processes
Interactive editing processes
batch processes
Low-priority batch processes
interactive processes
Lowest priority
Runnableprocesse
Disadvantage?
Schedulin g : 5. Priority Alg.
5 M
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 27/30
27
Dynamic multi level scheduling
The main drawback of priority scheduling: starvation !
To avoid it:
Prevent high priority processes from running indefinitely bychanging priorities dynamically :
o Each process has a base priorityo increase priorities of waiting processes at each clock tick
Approximation SJF schedulingo increase priorities of I/O bound processes
(decrease those of CPU bound processes) priority = 1/f ( f is the fraction of time-quantum used)
5. M
Schedulin g : 5. Priority Alg.
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 28/30
Sample QuestionIn SJF (Shortest Job First) Scheduling method.How to calculate Average Waiting Time and averageTurn-around time?
Is the following Gannt Chart correct ?
28
8/13/2019 Week 2 (2013-2014) Operating System
http://slidepdf.com/reader/full/week-2-2013-2014-operating-system 29/30