operating systems hybrid notes for computerscience.pdf

rayanrajab1 32 views 103 slides Sep 22, 2024
Slide 1
Slide 1 of 103
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101
Slide 102
102
Slide 103
103

About This Presentation

Operating systems notes for Computer Science


Slide Content

2010-2011
Lecture Notes on Operating Systems

Lecture 1: Introduction to Operating Systems
•Anoperatingsystemisaprogramthatactsasan
intermediarybetweenauserofacomputerandthe
computerhardware.
•Thepurposeofanoperatingsystemistoprovidean
environmentinwhichausercanexecuteprograms.
Theprimarygoalofanoperatingsystemisthusto
makethecomputersystemconvenienttouse.
•Asecondarygoalistousethecomputerhardwarein
anefficientmanner.

Lecture 1: Introduction to Operating Systems
•Inbrief,anoperatingsystemisthesetofprograms
thatcontrolsacomputer.Someexamplesof
operatingsystemsareUNIX,Mach,MS-DOS,MS-
Windows,Windows/NT,OS/2andMacOS.
•Anoperatingsystemisanimportantpartofalmost
everycomputersystem.
•Acomputersystemcanbedividedroughlyintofour
components:thehardware,theoperatingsystem,
theapplicationprogramsandtheusers(Figure1.1).

Objectives of Operating Systems
•Tohidedetailsofhardwarebycreatingabstraction.
•Toallocateresourcestoprocesses(Manage
resources).
•Provideapleasantandeffectiveuserinterface.

History of Operating Systems
•The1940's-FirstGenerations
Theearliestelectronicdigitalcomputershadnooperatingsystems.
Machinesofthetimeweresoprimitivethatprogramswereoftenentered
onebitattimeonrowsofmechanicalswitches(plugboards).
Programminglanguageswereunknown(notevenassemblylanguages).
Operatingsystemswereunheardof.
•The1950's-SecondGeneration
Bytheearly1950's,theroutinehadimprovedsomewhatwiththe
introductionofpunchcards.TheGeneralMotorsResearchLaboratories
implementedthefirstoperatingsystemsinearly1950'sfortheirIBM701.
Thesystemofthe50'sgenerallyranonejobatatime.

•The1960's-ThirdGeneration
Thesystemsofthe1960'swerealsobatchprocessingsystems,butthey
wereabletotakebetteradvantageofthecomputer'sresourcesbyrunning
severaljobsatonce.
•FourthGeneration
WiththedevelopmentofLSI(LargeScaleIntegration)circuits,chips,
operatingsystementeredinthepersonalcomputerandtheworkstation
age.Microprocessortechnologyevolvedtothepointthatitbecomes
possibletobuilddesktopcomputersaspowerfulasthemainframesofthe
1970s.
History of Operating Systems

Lecture 2: Operating Systems Structure
•SystemComponents
•OperatingSystemsServices
•SystemCallsandSystemPrograms

System Components
•ProcessManagement
AprocessisonlyONEinstantofaprograminexecution.
Therearemanyprocessescanberunningthesameprogram.
Thefivemajoractivitiesofanoperatingsysteminregardtoprocess
managementare:
•Creationanddeletionofuserandsystemprocesses.
•Suspensionandresumptionofprocesses.
•Amechanismforprocesssynchronization.
•Amechanismforprocesscommunication.
•Amechanismfordeadlockhandling.

System Components
•Main-MemoryManagement
Main-Memoryisalargearrayofwordsorbytes.Eachwordorbyte
hasitsownaddress.Mainmemoryisarepositoryofquicklyaccessible
datasharedbytheCPUandI/Odevices.
Themajoractivitiesofanoperatingsysteminregardtomemory-management
are:
•Keeptrackofwhichpartofmemoryarecurrentlybeingusedandbywhom.
•Decidewhichprocessesareloadedintomemorywhenmemoryspace
becomesavailable.
•Allocateanddeallocatememoryspaceasneeded.

System Components
•File Management
Afileisacollectedofrelatedinformationdefinedbyits
creator.Computercanstorefilesonthedisk(secondary
storage),whichprovidelongtermstorage.
•The creation and deletion of files.
•The creation and deletion of directions.
•The support of primitives for manipulating files and directions.
•The mapping of files onto secondary storage.
•The backup of files on stable storage media.

System Components
•I/OSystemManagement
Oneofthepurposesofanoperatingsystemistohidethe
peculiaritiesofspecifichardwaredevicesfromtheuser.
•Secondary-StorageManagement
Generallyspeaking,systemshaveseverallevelsof
storage,includingprimarystorage,secondarystorageand
cachestorage.Instructionsanddatamustbeplacedinprimary
storageorcachetobereferencedbyarunningprogram.

System Components
•Networking
Adistributedsystemisacollectionofprocessorsthatdonotshare
memory,peripheraldevices,oraclock.Theprocessorscommunicatewith
oneanotherthroughcommunicationlinescallednetwork.
•ProtectionSystem
Protectionreferstomechanismforcontrollingtheaccessof
programs,processes,oruserstotheresourcesdefinedbyacomputer
system.
•CommandInterpreterSystem
Acommandinterpreterisaninterfaceoftheoperatingsystemwith
theuser.Theusergivescommandswithareexecutedbyoperatingsystem
(usuallybyturningthemintosystemcalls).

Operating Systems Services
•ProgramExecution
Thesystemmustbeabletoloadaprogramintomemoryandtorun
it.Theprogrammustbeabletoenditsexecution,eithernormallyor
abnormally(indicatingerror).
•I/OOperations
ArunningprogrammayrequireI/O.ThisI/Omayinvolveafileoran
I/Odevice.
•FileSystemManipulation
Theoutputofaprogrammayneedtobewrittenintonewfilesor
inputtakenfromsomefiles.Theoperatingsystemprovidesthisservice.
•ErrorDetection
Anerrorisonepartofthesystemmaycausemalfunctioningofthe
completesystem.Toavoidsuchasituationtheoperatingsystemconstantly
monitorsthesystemfordetectingtheerrors.

System Calls and System Programs
•Systemcallsprovidetheinterfacebetweenaprocessandthe
operatingsystem.Thesecallsaregenerallyavailableas
assembly-languageinstructions,andareusuallylistedinthe
manualsusedbyassembly-languageprogrammers.

Lecture 3:Process Management
•Theoperatingsystemisresponsibleforthefollowingactivitiesin
connectionwithprocessmanagement:thecreationanddeletionofboth
userandsystemprocesses;theschedulingofprocesses;andtheprovision
ofmechanismsforsynchronization,communication,anddeadlock
handlingforprocesses.
Process,ontheotherhand,includes:
•CurrentvalueofProgramCounter(PC)
•Contentsoftheprocessorsregisters
•Valueofthevariables
•Theprocessesstack(SP)whichtypicallycontainstemporarydatasuchas
subroutineparameter,returnaddress,andtemporaryvariables.
•Adatasectionthatcontainsglobalvariables.

••ProcessProcessStateState
Asaprocessexecutes,itchangesstate.Thestateofa
processisdefinedinpartbythecurrentactivityofthat
process.Eachprocessmaybeinoneofthefollowingstates:
•NewState:Theprocessbeingcreated.
•RunningState:AprocessissaidtoberunningifithastheCPU,thatis,
processactuallyusingtheCPUatthatparticularinstant.
•Blocked(orwaiting)State:Aprocessissaidtobeblockedifitiswaitingfor
someeventtohappensuchthatasanI/Ocompletionbeforeitcan
proceed.Notethataprocessisunabletorununtilsomeexternalevent
happens.
•ReadyState:Aprocessissaidtobereadyifitiswaitingtobeassignedtoa
processor.
•Terminatedstate:Theprocesshasfinishedexecution.

Figure : Diagram of process states.

•ProcessControlBlock
•Eachprocessisrepresentedintheoperatingsystembya
processcontrolblockPCS)—alsocalledataskcontrolblock.
Process state
process number
program counter
Registers
memory limits
list of open files
.
.
Figure : Process control block.

Lecture 4: CPU Scheduling
•CPUschedulingisthebasisofmultiprogrammedoperating
systems.ByswitchingtheCPUamongprocesses,theoperating
systemcanmakethecomputermoreproductive.
•BasicConcepts
Theideaofmultiprogrammingisrelativelysimple.A
processisexecuteduntilitmustwait,typicallyforthe
completionofsomeI/Orequest.Inasimplecomputersystem,
theCPUwouldthenjustsitidle.
Schedulingisafundamentaloperating-systemfunction.
Almostallcomputerresourcesarescheduledbeforeuse.

•CPU-I/OBurstCycle
ThesuccessofCPUschedulingdependsonthefollowing
observedpropertyofprocesses:Processexecutionconsistsof
acycleofCPUexecutionandI/Owait.Processesalternate
backandforthbetweenthesetwostates.
•ContextSwitch
Togiveeachprocessonamultiprogrammedmachinea
fairshareoftheCPU,ahardwareclockgeneratesinterrupts
periodically.
Thisallowstheoperatingsystemtoscheduleallprocesses
inmainmemory(usingschedulingalgorithm)torunonthe
CPUatequalintervals.EachswitchoftheCPUfromone
processtoanotheriscalledacontextswitch.

•PreemptiveScheduling
CPUschedulingdecisionsmaytakeplaceunderthe
followingfourcircumstances:
1.Whenaprocessswitchesfromtherunningstatetothewaitingstate(for.
example,I/Orequest,orinvocationofwaitfortheterminationofoneof
thechildprocesses).
2.Whenaprocessswitchesfromtherunningstatetothereadystate(for
example,whenaninterruptoccurs).
3.Whenaprocessswitchesfromthewaitingstatetothereadystate(for
example,completionofI/O).
4.Whenaprocessterminates.

•Dispatcher
•Switchingcontext.
•Switchingtousermode.
•Jumpingtotheproperlocationintheuserprogramtorestartthatprogram
•SchedulingCriteria
•DifferentCPUschedulingalgorithmshavedifferentpropertiesandmay
favoroneclassofprocessesoveranother.Inchoosingwhichalgorithmto
useinaparticularsituation,wemustconsiderthepropertiesofthe
variousalgorithms.

•ManycriteriahavebeensuggestedforcomparingCPU
schedulingalgorithms.
•Criteriathatareusedincludethefollowing:
•CPUutilization.
•Throughput.
•Turnaroundtime.
•Waitingtime.
•Responsetime.

Lecture 5: Scheduling Algorithms
1.First-Come,First-ServedScheduling
2.Shortest-Job-FirstScheduling
3.PriorityScheduling
4.Round-RobinScheduling
5.MultilevelQueueScheduling
6.MultilevelFeedbackQueueScheduling

First-Come, First-Served Scheduling
ProcessBurst Time
P1 24
P2 3
P3 3
P1 P2P3
0 242730

Shortest-Job-First Scheduling
ProcessBurst Time
P1 6
P2 8
P3 7
P4 3
P4 P1 P3 P2
0 3 9 16 24

Priority Scheduling
ProcessBurst Time Priority
P1 10 3
P2 1 1
P3 2 3
P4 1 4
P5 5 2
P2 P5 P1 P3 P4

Round-Robin Scheduling
ProcessBurst Time
P1 24
P2 3
P3 3

Multilevel Queue Scheduling

•Inamultilevelqueueschedulingprocessesarepermanently
assignedtoonequeues.
•Theprocessesarepermanentlyassignedtooneanother,
basedonsomepropertyoftheprocess,suchas
•Memorysize
•Processpriority
•Processtype
•Algorithmchoosestheprocessfromtheoccupiedqueuethat
hasthehighestpriority,andrunthatprocesseither
•Preemptiveor
•Non-preemptively

6. Process Synchronization
•Acooperatingprocessisonethatcanaffectorbe
affectedbytheotherprocessesexecutinginthe
system.
•Cooperatingprocessesmayeitherdirectlysharea
logicaladdressspace(thatis,bothcodeanddata),or
beallowedtosharedataonlythroughfiles.The
formercaseisachievedthroughtheuseof
lightweightprocessesorthreads.Concurrentaccess
toshareddatamayresultindatainconsistency.
•Inthislecture,wediscussvariousmechanismsto
ensuretheorderlyexecutionofcooperating
processesthatsharealogicaladdressspace,sothat
dataconsistencyismaintained.

CooperatingProcesses
•Theconcurrentprocessesexecutingintheoperating
systemmaybeeitherindependentprocessesor
cooperatingprocesses.
•Aprocessisindependentifitcannotaffectorbe
affectedbytheotherprocessesexecutinginthe
system.
•Ontheotherhand,aprocessiscooperatingifitcan
affectorbeaffectedbytheotherprocessesexecuting
inthesystem.

•Thereareseveralreasonsforprovidinganenvironmentthat
allowsprocesscooperation:
Information sharing
Computationspeedup
Modularity
Convenience

Race condition
•Whenseveralprocessesaccessand
manipulatethesamedataconcurrentlyand
theoutcomeoftheexecutiondependsonthe
particularorderinwhichtheaccesstakes
place,iscalledaracecondition.

The Critical-Section Problem
•Theimportantfeatureofthesystemisthat,whenoneprocess
isexecutinginitscriticalsection,nootherprocessistobe
allowedtoexecuteinitscriticalsection.
•Thus,theexecutionofcriticalsectionsbytheprocessesis
mutuallyexclusiveintime.
•Thecritical-sectionproblemistodesignaprotocolthatthe
processescanusetocooperate.
•Eachprocessmustrequestpermissiontoenteritscritical
section.

•Asolutiontothecritical-sectionproblemmustsatisfy
thefollowingthreerequirements:
1.MutualExclusion:IfprocessPiisexecutinginitscritical
section,thennootherprocessescanbeexecutingintheir
criticalsections.
2.Progress:Ifnoprocessisexecutinginitscriticalsectionand
thereexistsomeprocessesthatwishtoentertheircritical
sections,thenonlythoseprocessesthatarenotexecutingin
theirremaindersectioncanparticipateinthedecisionof
whichwillenteritscriticalsectionnext,andthisselection
cannotbepostponedindefinitely.
3.BoundedWaiting:Thereexistaboundonthenumberoftimes
thatotherprocessesareallowedtoentertheircriticalsections
afteraprocesshasmadearequesttoenteritscriticalsection
andbeforethatrequestisgranted.

DEADLOCKS
•Aprocessrequestsresources;iftheresourcesarenot
availableatthattime,theprocessentersawaitstate.Itmay
happenthatwaitingprocesseswillneveragainchangestate,
•becausetheresourcestheyhaverequestedareheldbyother
waitingprocesses.Thissituationiscalledadeadlock.
•Inthislecture,wedescribemethodsthatanoperatingsystem
canusetodealwiththedeadlockproblem.

Resources
•A process must request a resource before using it, and must
release the resource after using it.
•A process may request as many resources as it requires to
carry out its designated task.
•a process may utilize a resource in only the following
sequence:
Use
Release
Request

DeadlockCharacterization
•Inadeadlock,processesneverfinishexecutingand
systemresourcesaretiedup,preventingotherjobs
fromeverstarting.
•Beforewediscussthevariousmethodsfordealing
withthedeadlockproblem,weshalldescribe
featuresthatcharacterizedeadlocks.

Necessary Conditions
•Adeadlocksituationcanariseifthefollowingfour
conditionsholdsimultaneouslyinasystem:
•Mutual exclusion
•Hold and wait
•No preemption
•Circular wait

Methods for Handling Deadlocks
•Principally,therearethreedifferentmethodsfor
dealingwiththedeadlockproblem:
•Wecanuseaprotocoltoensurethatthesystemwillnever
enteradeadlockstate.
•Wecanallowthesystemtoenteradeadlockstateandthen
recover.
•Ignoretheproblemandpretendthatdeadlocksneveroccurin
thesystem;usedbymostoperatingsystems,includingUNIX.

DeadlockPrevention
•Byensuringthatatleastoneoftheseconditionscannothold,
wecanpreventtheoccurrenceofadeadlock
MutualExclusion–notrequiredforsharableresources;mustholdfor
nonsharableresources.
HoldandWait–mustguaranteethatwheneveraprocessrequestsa
resource,itdoesnotholdanyotherresources.
NoPreemption–oIfaprocessthatisholdingsomeresourcesrequests
anotherresourcethatcannotbeimmediatelyallocatedtoit,thenall
resourcescurrentlybeingheldarereleased.
•CircularWait–imposeatotalorderingofallresourcetypes,andrequire
thateachprocessrequestsresourcesinanincreasingorderof
enumeration.

Deadlock Avoidance
•Requires that the system has some additional a priori
information available.
Simplestandmostusefulmodelrequiresthateachprocessdeclare
themaximumnumberofresourcesofeachtypethatitmayneed.
Thedeadlock-avoidancealgorithmdynamicallyexaminesthe
resource-allocationstatetoensurethattherecanneverbea
circular-waitcondition.
Resource-allocationstateisdefinedbythenumberofavailableand
allocatedresources,andthemaximumdemandsoftheprocesses.

Deadlock Detection
•Ifasystemdoesnotemployeitheradeadlock-preventionora
deadlockavoidancealgorithm,thenadeadlocksituationmay
occur.Inthisenvironment,thesystemmustprovide:
Analgorithmthatexaminesthestateofthesystemto
determinewhetheradeadlockhasOccurred.
Analgorithmtorecoverfromthedeadlock

Memory ManagementMemory Management

Programmustbebrought(fromdisk)intomemory
andplacedwithinaprocessforittoberun.
MainmemoryandregistersareonlystorageCPUcan
accessdirectly.RegisteraccessinoneCPUclock(or
less).
Mainmemorycantakemanycycles.
CachesitsbetweenmainmemoryandCPUregisters.
Protectionofmemoryrequiredtoensurecorrect
operation.

Virtual Memory

Protection
Domain of Protection
Security
cryPtograPhy
authentication