+ All Categories
Home > Documents > Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What...

Operating Systems Intro - Swarthmore Collegemgagne1/teaching/2016_17/cs31/p… · 11/1/2016. What...

Date post: 18-Jul-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
26
Operating Systems Intro 11/1/2016
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Upnext…

• Howwecreate/manageprocesses.

• Howweprovidetheillusionofthesameenormousmemoryspaceforallprocesses.


Recommended