0% found this document useful (0 votes)
72 views53 pages

Basic Operating System Concepts: A Review

The document provides an overview of basic operating system concepts. It discusses the main goals of an OS including resource management and abstraction. It describes system calls as entry points to the OS kernel and how they allow mode switching. Some common system calls for file I/O, process control, and IPC are listed. Process scheduling, synchronization, and memory management techniques are reviewed at a high level.

Uploaded by

Pradnya Joshi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views53 pages

Basic Operating System Concepts: A Review

The document provides an overview of basic operating system concepts. It discusses the main goals of an OS including resource management and abstraction. It describes system calls as entry points to the OS kernel and how they allow mode switching. Some common system calls for file I/O, process control, and IPC are listed. Process scheduling, synchronization, and memory management techniques are reviewed at a high level.

Uploaded by

Pradnya Joshi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 53

Basic Operating System Concepts

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

Some #4/5 System Calls


- System calls for low level file /1O
, , , , , , creat6name! permissions7 open6name! mo%e7 close6f%7 unlin 6f%7 rea%6f%! $uffer! n8to8rea%7 write6f%! $uffer! n8to8write7 , lsee 6f%! offest! w)ence7

- System Calls for process control


, for 67 , wait67 , e&ecl67! e&eclp67! e&ecv67! e&ecvp67 , e&it67 , signal6sig! )an%ler7 , ill6sig! pi%7

- System Calls for /"C


, pipe6fil%es7 , %up6f%7

9&ecution Mo%es 6Dual Mo%e 9&ecution7


- #ser mo%e vs. ernel 6or supervisor7 mo%e - "rotection mec)anism: critical operations 6e.g. %irect %evice access! %isa$ling interrupts7 can only $e performe% $y t)e OS w)ile e&ecuting in ernel mo%e - Mo%e $it - "rivilege% instructions

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

"rocessing a System Call<


- Switc)ing $etween ernel an% user mo%e is time consuming - =ernel must
, Save registers so process can resume e&ecution
- Ot)er over)ea% is involve%> e.g. cac)e misses! ? prefetc)

, +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

"rocesses: "rocess /mage


- 3)e process image represents t)e current status of t)e process - /t consists of 6among ot)er t)ings7
, , , , 9&ecuta$le co%e Static %ata area Stac ? )eap area "rocess Control Bloc 6"CB7: %ata structure use% to represent e&ecution conte&t! or state , Ot)er information nee%e% to manage process

"rocess 9&ecution States


- @or convenience! we %escri$e a process as $eing in one of several $asic states. - Most $asic:
, Running , Rea%y , Bloc e% 6or sleeping7

"rocess State 3ransition Diagram


preempt rea%y %ispatc) event occurs $loc e% wait for event running

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

- A conte&t switc) involves two processes:


, One leaves t)e Running state , Anot)er enters t)e Running state

- 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.

"rocesses an% 3)rea%s


- 3ra%itional processes coul% only %o one t)ing at a time , t)ey were single2t)rea%e%. - Multit)rea%e% processes can 6conceptually7 %o several t)ings at once , t)ey )ave multiple t)rea%s. - A t)rea% is an :e&ecution conte&t; or :separately sc)e%ula$le; entity.

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

3)rea%s versus "rocesses


- /f two processes want to access s)are% %ata structures! t)e OS must $e involve%.
, Over)ea%: system calls! mo%e switc)es! conte&t switc)es! e&tra e&ecution time.

- 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

"rocess 63)rea%7 Sc)e%uling


- "rocess sc)e%uling %eci%es w)ic) process to %ispatc) 6to t)e Run state7 ne&t. - /n a multiprogramme% system several processes compete for a single processor - "reemptive sc)e%uling: a process can $e remove% from t)e Run state $efore it completes or $loc s 6timer e&pires or )ig)er priority process enters Rea%y state7.

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

/nterprocess Communication 6/"C7


- "rocesses 6or t)rea%s7 t)at cooperate to solve pro$lems must e&c)ange information. - 3wo approac)es:
, S)are% memory , Message passing 6copying information from one process a%%ress space to anot)er7

- 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

"rocess Sync)roni'ation , ( 3ypes


- Correct sync)roni'ation may mean t)at we want to $e sure t)at event ( in process A )appens $efore event D in process B. - Or! it coul% mean t)at w)en one process is accessing a s)are% resource! no ot)er process s)oul% $e allowe% to access t)e same resource. 3)is is t)e critical section problem! an% re.uires mutual e clusion.

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%

Ot)er Mec)anisms for Mutual 9&clusion


- Spinlocks: a busy$waiting solution in w)ic) a process wis)ing to enter a critical section continuously tests some loc varia$le to see if t)e critical section is availa$le. /mplemente% wit) various mac)ine2language instructions - Disable interrupts $efore entering CS! ena$le after leaving

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

Dea%loc versus Starvation


- Starvation occurs w)en a process is repeate%ly %enie% access to a resource even t)oug) t)e resource $ecomes availa$le. - Dea%loc e% processes are permanently $loc e% $ut starving processes may eventually get t)e resource $eing re.ueste%. - /n starvation! t)e resource $eing waite% for is continually in use! w)ile in %ea%loc it is not $eing use% $ecause it is assigne% to a $loc e% process.

Causes of Dea%loc
Mutual e&clusion 6e&clusive access7 Bait w)ile )ol% 6)ol% an% wait7 4o preemption Circular wait

Dea%loc Management Strategies


- Prevention: %esign a system in w)ic) at least one of t)e D causes can never )appen - Avoidance: allocate resources carefully! so t)ere will always $e enoug) to allow all processes to complete 6Ban er0s Algorit)m7 - Detection: perio%ically! %etermine if a %ea%loc e&ists. /f t)ere is one! a$ort one or more processes! or ta e some ot)er action.

Analysis of Dea%loc Management


- Most systems %o not use any form of %ea%loc management $ecause it is not cost effective
, 3oo time2consuming , 3oo restrictive

- 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

Memory Management 2 /ntro


- "rimary memory must $e s)are% $etween t)e OS an% user processes. - OS must protect itself from users! an% one user from anot)er. - OS must also manage t)e s)aring of p)ysical memory so t)at processes are a$le to e&ecute wit) reasona$le efficiency.

Allocation Met)o%s: Single "rocess


- 9arliest systems use% a simple approac): OS )a% a protecte% set of memory locations! t)e remain%er of memory $elonge% to one process at a time. - "rocess :owne%; all computer resources from t)e time it $egan until it complete%

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

- Motivation for virtual memory:


, to $etter utili'e memory 6re%uce fragmentation7 , to increase t)e num$er of processes t)at coul% e&ecute concurrently

- Met)o%:
, allow program to $e loa%e% non2contiguously , allow program to e&ecute even if it is not entirely in memory.

+irtual Memory 2 "aging


- 3)e a%%ress space of a program is %ivi%e% into :pages; , a set of contiguous locations. - "age si'e is a power of (> typically at least D=. - Memory is %ivi%e% into page frames of same si'e. - Any :page; in a program can $e loa%e% into any :frame; in memory! so no space is waste%.

"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

Solutions to "aging "ro$lems


- Mow to tell w)at0s :nee%e%;
, Deman% paging

- Mow to eep trac of w)ere t)e pages are


, 3)e page ta$le

- Mow to translate virtual a%%resses to p)ysical


, MM# 6memory management unit7 uses logical a%%resses an% page ta$le %ata to form actual p)ysical a%%resses. All %one in )ar%ware.

OS Responsi$ilities in "age% +irtual Memory


- Maintain page ta$les - Manage page replacement

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.

@ile Systems , Dis Management


- 3)e file system is also responsi$le for allocating %is space an% eeping trac of w)ere files are locate%. - Dis storage management )as many of t)e pro$lems main memory management )as! inclu%ing fragmentation issues.

9n% of OS Review

You might also like