operating systems intro - swarthmore collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. what...
TRANSCRIPT
![Page 1: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/1.jpg)
OperatingSystemsIntro11/1/2016
![Page 2: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/2.jpg)
Whatisanoperatingsystem?
TheOSisaninterfacelayerbetweenauser’sprogramsandhardware.
Itprovidesanabstractviewofthehardwarethatmakesiteasiertouse.
ProgramOperatingSystem
ComputerHardware
![Page 3: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/3.jpg)
Howmanyprogramsdoyouthinkarerunningonmylaptopnow?A. 0-1
B. 2-9
C. 10-99
D. 100-999
E. 1000+
![Page 4: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/4.jpg)
Sharingresources
Alloftheseprogramsneedtoshare:• Memory• Processortime• I/Odevices
Butwhenyouwriteaprogram,youdon’thavetothinkaboutthehundredsofotherprogramsthatcouldberunning.
![Page 5: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/5.jpg)
BeforeOperatingSystems
![Page 6: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/6.jpg)
OSprovidesvirtualization
• Ratherthanexposingrealhardware,introducea“virtual”,abstractnotionoftheresource
• Multiplevirtualprocessors• ByrapidlyswitchingCPUuse
• Multiplevirtualmemories• Bymemorypartitioningandre-addressing
• Virtualizeddevices• Bysimplifyinginterfaces,andusingotherresourcestoenhancefunction
![Page 7: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/7.jpg)
We’llfocusontheOS‘kernel’
• “Operatingsystem”hasmanyinterpretations• E.g.,allsoftwareonmachineminusapplications
• Ourfocusisthekernel• What’snecessaryforeverythingelsetowork• Low-levelresourcecontrol
![Page 8: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/8.jpg)
TheKernel
• Allprogramsdependonit• Loadsandrunsthem• Exportssystemcallstoprograms
• Workscloselywithhardware• Accessesdevices• Respondstointerrupts
• Allocatesbasicresources• CPUtime,memoryspace• ControlsI/Odevices:display,keyboard,disk,network
![Page 9: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/9.jpg)
Kernelprovidescommonfunctions
• Somefunctionsusefultomanyprograms• I/Odevicecontrol• Memoryallocation
• Placethesefunctionsincentralplace(kernel)• Calledbyprograms(systemcalls)• Oraccessedimplicitly
• Whatfunctionsshouldbeincluded?• Howmanyprogramsneedtobenefit?• Mightkernelgettoobig?
![Page 10: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/10.jpg)
MainAbstraction:TheProcess
• Abstractionofarunningprogram• “aprograminexecution”
• Dynamic• Hasstate,changesovertime• Whereasaprogramisstatic
• Basicoperations• Start/end• Suspend/resume
![Page 11: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/11.jpg)
BasicResourcesforProcesses
Torun,processneedssomebasicresources:• CPU• Processingcycles(time)• Toexecuteinstructions
• Memory• Bytesorwords(space)• Tomaintainstate
• Otherresources(e.g.,I/O)• Network,disk,terminal,printer,etc.
![Page 12: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/12.jpg)
MachineStateofaProcess
• CPUorprocessorcontext• PC(programcounter)• SP(stackpointer)• Generalpurposeregisters
• Memory• Code• GlobalVariables• Stackofactivationrecords/frames• Other(registers,memory,kernel-relatedstate)
Mustkeeptrackoftheseforeveryrunningprocess!
![Page 13: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/13.jpg)
CPU• Abstractiongoal:makeeveryprocessthinkit’srunningontheCPUallthetime.• Alternatively:IfaprocesswasremovedfromtheCPUandthengivenitback,itshouldn’tbeabletotell
• Reality:putaprocessonCPU,letitrunforashorttime(~10ms),switchtoanother,… (contextswitching)
![Page 14: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/14.jpg)
Timesharing:SharingtheCPU
• Multipleprocesses,singleCPU(uniprocessor)• Conceptually,eachprocessmakesprogressovertime• Inreality,eachperiodicallygetsquantumofCPUtime• IllusionofparallelprogressbyrapidlyswitchingCPU
P1 P2
P3
P1 P2 P3quantum
P1P2P3
time
![Page 15: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/15.jpg)
Memory• Abstractiongoal:makeeveryprocessthinkithasthesamememorylayout.• MUCHsimplerforcompilerifthestackalwaysstartsat0xFFFFFFFF,etc.
Text
Data
Stack
OS
Heap
![Page 16: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/16.jpg)
Memory• Abstractiongoal:makeeveryprocessthinkithasthesamememorylayout.• MUCHsimplerforcompilerifthestackalwaysstartsat0xFFFFFFFF,etc.
• Reality:there’sonlysomuchmemorytogoaround,andnotwoprocessesshouldusethesame(physical)memoryaddresses(unlessthey’resharingonpurpose).
Process1
Process3
Process3
OS
Process2
Process1
OS(withhelpfromhardware)willkeeptrackofwho’susingeachmemoryregion.
![Page 17: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/17.jpg)
VirtualMemory:SharingStorage
• LikeCPUcache,memoryisacachefordisk.
• Processesneverneedtoknowwheretheirmemorytrulyis,OStranslatesvirtualaddressesintophysicaladdressesforthem.
P1 P2 P3
P1 P2P3
![Page 18: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/18.jpg)
TheKernel
• So…how/whenshouldthekernelexecute?
• Whatwouldyoudoifyouweretobuildsuchathing?
![Page 19: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/19.jpg)
Theoperatingsystemkernel…
A. Executesasaprocess.
B. Isalwaysexecuting,insupportofotherprocesses.
C. Shouldexecuteaslittleaspossible.
D. Morethanoneoftheabove.(Whichones?)
E. Noneoftheabove.
![Page 20: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/20.jpg)
Processvs.Kernel
• Thekernelisthecodethatsupportsprocesses• Systemcalls:fork(),exit(),read(),write(),…• Systemmanagement:contextswitching,scheduling
• Whendoesthekernelrun?• Whensystemcallorhardwareinterruptoccurs
• Isthekernelaprocess?• No,itsupportsprocessesanddevices• Runsasanextensionofprocessmakingsystemcall• Runsinresponsetodeviceissuinginterrupt
![Page 21: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/21.jpg)
ProcessandKernelModel
Text
Data
Stack
Process1
TextData
Stack
Process2
Text
Data
Stack
Processn
…
KernelSystemCalls
write
read
forkSystem
Management Scheduling
ContextSwitching
OS OS
HeapHeap
OS
HeapMakessystemcall.OSaccessesdevice,assignsresource,etc.
![Page 22: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/22.jpg)
ProcessandKernelModel
Text
Data
Stack
Process1
TextData
Stack
Process2
Text
Data
Stack
Processn
…
KernelSystemCalls
write
read
forkSystem
Management Scheduling
ContextSwitching
OS OS
HeapHeap
OS
Heap
OShascontrol.Itcancontextswitch(andusuallydoesatthispoint).
![Page 23: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/23.jpg)
ProcessandKernelModel
Text
Data
Stack
Process1
TextData
Stack
Process2
Text
Data
Stack
Processn
…
KernelSystemCalls
write
read
forkSystem
Management Scheduling
ContextSwitching
OS OS
HeapHeap
OS
Heap
OSreturnscontroltoaprocess(notusuallythesameone).
![Page 24: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/24.jpg)
ProcessandKernelModel
Text
Data
Stack
Process1
TextData
Stack
Process2
Text
Data
Stack
Processn
…
KernelSystemCalls
write
read
forkSystem
Management Scheduling
ContextSwitching
OS OS
HeapHeap
OS
Heap Transitionisexpensive,butoftennecessary.
![Page 25: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/25.jpg)
HowDoesKernelGetControl
• Toswitchprocesses,kernelmustgetcontrol• Runningprocesscangiveupcontrolvoluntarily• Processmakesablockingsystemcall,e.g.,read()• Toblock,callyield()togiveupCPU• Controlgoestokernel,whichdispatchesnewprocess
• Or,CPUisforciblytakenaway:preemption• Whilekernelisrunning,itsetsatimer• Whentimerexpires,interruptisgenerated• Hardwareforcescontroltogotokernel
![Page 26: Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What is an operating system? The OS is an interface layer between a user’s programs](https://reader033.vdocuments.net/reader033/viewer/2022050202/5f564d08a3678907fc0f8b88/html5/thumbnails/26.jpg)
Upnext…
• Howwecreate/manageprocesses.
• Howweprovidetheillusionofthesameenormousmemoryspaceforallprocesses.