Professional Documents
Culture Documents
A Review
Main Goals of OS
1. Resource Management: Dis ! C"# cycles! etc. must $e manage% efficiently to ma&imi'e overall system performance (. Resource A$straction: Software interface to simplify use of )ar%ware resources *. +irtuali'ation: Supports resource s)aring , gives eac) process t)e appearance of an uns)are% resource
System Call
- An entry point to OS co%e - Allows users to re.uest OS services - A"/0s1li$rary functions usually provi%e an interface to system calls
, e.g! language2level /1O functions map user parameters into system2call format
- 3)us! t)e run2time support system of a prog. language acts as an interface $etween programmer an% OS interface
Mo%e Switc)ing
- System calls allow $oun%ary to $e crosse%
, System call initiates mode switch from user to ernel mo%e , Special instruction , :software interrupt; , calls t)e ernel function
- transfers control to a location in t)e interrupt vector
, OS e&ecutes ernel co%e! mo%e switc) occurs again w)en control returns to user process
, +erify system call name an% parameters , Call t)e ernel function to perform t)e service , On completion! restore registers an% return to caller
Review 3opics
"rocesses ?3)rea%s Sc)e%uling Sync)roni'ation Memory Management @ile an% /1O Management
Review of "rocesses
- "rocesses
, process image , states an% state transitions , process switc) 6conte&t switc)7
- 3)rea%s - Concurrency
"rocess Definition
- A process is an instance of a program in e&ecution. - /t encompasses t)e static concept of program an% t)e %ynamic aspect of e&ecution. - As t)e process runs! its conte&t 6state7 c)anges , register contents! memory contents! etc.! are mo%ifie% $y e&ecution
Ot)er States
- 4ew - 9&it - Suspen%e% 6Swappe%7
, Suspen%e% $loc e% , Suspen%e% rea%y
Conte&t Switc)
6sometimes calle% process switc)7
- 3)e status 6conte&t7 of one process is save%> t)e status of t)e secon% process restore%. - Don0t confuse wit) mo%e switc).
Concurrent "rocesses
- 3wo processes are concurrent if t)eir e&ecutions overlap in time. - /n a uniprocessor environment! multiprogramming provi%es concurrency. - /n a multiprocessor! true parallel e&ecution can occur.
@orms of Concurrency
Multi programming: Creates logical parallelism $y running several processes1t)rea%s at a time. 3)e OS eeps several Ao$s in memory simultaneously. /t selects a Ao$ from t)e rea%y state an% starts e&ecuting it. When that job needs to wait for some event the CPU is switched to another job. "rimary o$Aective: eliminate C"# i%le time Time sharing: An e&tension of multiprogramming. After a certain amount of time the CPU is switched to another job regardless of whether the process/thread needs to wait for some operation. Switc)ing $etween Ao$s occurs so fre.uently t)at t)e users can interact wit) eac) program w)ile it is running. Multiprocessing: Multiple processors on a single computer run multiple processes at t)e same time. Creates p)ysical parallelism.
"rotection
- B)en multiple processes 6or t)rea%s7 e&ist at t)e same time! an% e&ecute concurrently! t)e OS must protect t)em from mutual interference. - Memory protection 6memory isolation7 prevents one process from accessing t)e p)ysical a%%ress space of anot)er process. - Base1limit registers! virtual memory are tec)ni.ues to ac)ieve memory protection.
3)rea%s
- Several t)rea%s can s)are t)e a%%ress space of a single process! along wit) resources suc) as files. - 9ac) t)rea% )as its own stac ! "C! an% 3CB 6t)rea% control $loc 7
, 9ac) t)rea% e&ecutes a separate section of t)e co%e an% )as private %ata , All t)rea%s can access glo$al %ata of process
- 3wo t)rea%s in a single process can s)are glo$al %ata automatically , as easily as two functions in a single process.
Review 3opics
"rocesses ?3)rea%s Sc)e%uling Sync)roni'ation Memory Management @ile an% /1O Management
Sc)e%uling Algorit)ms:
- @C@S 6first2come! first2serve%7: non2 preemptive: processes run until t)ey complete or $loc t)emselves for event wait - RR 6roun% ro$in7: preemptive @C@S! $ase% on time slice
, 3ime slice C lengt) of time a process can run $efore $eing preempte% , Return to Rea%y state w)en preempte%
Sc)e%uling Goals
- Optimi'e turnaroun% time an%1or response time - Optimi'e t)roug)put - Avoi% starvation 6$e :fair; 7 - Respect priorities
, Static , Dynamic
Review 3opics
"rocesses ?3)rea%s Sc)e%uling Sync)roni'ation Memory Management @ile an% /1O Management
- S)are% memory is more efficient 6no copying7! $ut isn0t always possi$le.
"rocess13)rea% Sync)roni'ation
- Concurrent processes are asynchronous: t)e relative or%er of events wit)in t)e two processes cannot $e pre%icte% in a%vance. - /f processes are relate% 6e&c)ange information in some way7 it may $e necessary to sync)roni'e t)eir activity at some points.
/nstruction Streams
"rocess A: A1! A(! A*! AD! AE! AF! AG! AH! I! Am "rocess B: B1! B(! B*! BD! BE! BF! I! Bn Se.uential /: A1! A(! A*! AD! AE! I! Am! B1! B(! B*! BD! BE! BF! I! Bn /nterleave% //: B1! B(! B*! BD! BE! A1! A(! A*! BF! I! Bn! AD! AE! I ///: A1! A(! B1! B(! B*! A*! AD! BD! BE! I! Bn! AE! AF! I! Am
Mutual 9&clusion
- A critical section is t)e co%e t)at accesses s)are% %ata or resources. - A solution to t)e critical section pro$lem must ensure t)at only one process at a time can e ecute its critical section !C"#. - 3wo separate s)are% resources can $e accesse% concurrently.
Sync)roni'ation
- "rocesses an% t)rea%s are responsi$le for t)eir own sync)roni'ation! $ut programming languages an% operating systems may )ave features to )elp. - +irtually all operating systems provi%e some form of semaphore! w)ic) can $e use% for mutual e&clusion an% ot)er forms of sync)roni'ation suc) as event or%ering.
Semap)ores
- Definition: A semap)ore is an integer varia$le 6S7 w)ic) can only $e accesse% in t)e following ways:
, /nitiali'e 6S7 , "6S7 11 Jwait6S7K , +6S7 11 Jsignal6S7K
- 3)e operating system must ensure t)at all operations are in%ivisi$le! an% t)at no ot)er access to t)e semap)ore varia$le is allowe%
Dea%loc
- A set of processes is %ea%loc e% w)en eac) is in t)e Bloc e% state $ecause it is waiting for a resource t)at is allocate% to one of t)e ot)ers. - Dea%loc s can only $e resolve% $y agents outsi%e of t)e %ea%loc
Causes of Dea%loc
Mutual e&clusion 6e&clusive access7 Bait w)ile )ol% 6)ol% an% wait7 4o preemption Circular wait
- 9&ceptions: some transaction systems )ave roll2$ac capa$ility or apply or%ering tec)ni.ues to control ac.uiring of loc s.
Review 3opics
"rocesses ?3)rea%s Sc)e%uling Sync)roni'ation Memory Management @ile an% /1O Management
Memory Management
- /ntro%uction - Allocation met)o%s
, One process at a time , Multiple processes! contiguous allocation , Multiple processes! virtual memory
Allocation Met)o%s:
Multiple "rocesses! Contiguous Allocation - Several processes resi%e% in memory at one time 6multiprogramming7. - 3)e entire process image for eac) process was store% in a contiguous set of locations. - Draw$ac s:
, Limite% num$er of processes at one time , @ragmentation of memory
Allocation Met)o%s:
Multiple "rocesses! +irtual Memory
- Met)o%:
, allow program to $e loa%e% non2contiguously , allow program to e&ecute even if it is not entirely in memory.
"aging 2 continue%
- General i%ea , save space $y loa%ing only t)ose pages t)at a program nee%s now. - Result , more programs can $e in memory at any given time - "ro$lems:
, Mow to tell w)at0s :nee%e%; , Mow to eep trac of w)ere t)e pages are , Mow to translate virtual a%%resses to p)ysical
Review 3opics
"rocesses ?3)rea%s Sc)e%uling Sync)roni'ation Memory Management @ile an% /1O Management
@ile Systems
- Maintaining a s)are% file system is a maAor Ao$ for t)e operating system. - Single user systems re.uire protection against loss! efficient loo 2up service! etc. - Multiple user systems also nee% to provi%e access control.
9n% of OS Review