You are on page 1of 16

CMSC421MidtermStuff

*mutex,semiphore,criticalsection,thediningthing
(deadlock)*

Nameofprofessor,emailaddress,nameofTA,emailaddressofTA

Prof:GeraldTompkins,Gerald@umbc.edu
TA:NikitaJituri,njituri1@umbc.edu

a.Abstraction
Takingsmallpieces,groupingthemtomakelargerunits
(chunkingandlayeringaretypesofabstraction)
b.Chunking
Usingbitesizedpiecesofcodeinsteadofonebigthing
c.Layering
Thingsaremadeoutofotherthings,whichcanbemadeoutof
otherthings
d.Complexity
Writingcomplicatedthingscanbemadeeasierdonebymaking
smaller,easierthings
e.Howabstractionisimportantindevelopingsoftware?
Helpsusseemeaning/purpose
Biggerunitsareeasiertounderstand(modularity?)
Hidingfinedetailsthatarenttooimportanttofocuson
Generalizingpatterns(ex:classes,inheritance)
Allowsustounderstandwhatwearedoing
Whatarethefirstprinciplesofsecurity?

Chapter1Introduction:
Thiswasawhirlwindchapter.Theconceptsherewillbecoveredin
moredetailinthefollowupchapters.Inotherwords,donotspenda
lotoftimehere.
Chapter2OSStructures
f.Page56Slide7.Noticehowtheservicesarelayered.For
example,everyuserinterfacecallmustusethesystemcall.All
systemcallsusetheservicesbelow.Therearenoskippinglayers.
Thelayerbelowprovidesservicesforthelayerabove.
OSservicesarelayered.Allusageofservicearedependentonthe
onesbelowit.

g.Whataresomesystemcallsandwhatdotheydo?(slide2024)
ProcessControl
FileManagement
DeviceManagement
InformationMaintenance
Communications

Createprocess/Terminateprocess
End,abort
Load,execute
GetProcessattributes,setprocessattributes
Waitfortime
Waitevent,signalevent
Allocateandfreememory
Dumpmemoryiferror
Debugger
fork():createaprocess
exec():loadaprogramintoaprocess
Locksformanagingaccesstoshareddatabetweenprocesses
h.Whatistheimportanceinhavinglibraries?
Reusingcode

i.Whatarethesystemprograms?
Systemprogramsdosystemcallsforusefulreasons
Providesconvenientenvironmentforprogram
developementandexecution
Canbe:Filemanip,statusinfo,languagesupport,comms,
services,apps
j.WhydowehaveMicroKernels?
Theymovestufffromkernelintouserspace
Modularity?EasiertoportOStonewarchitectures
Easiertoextend(Ithink:addontothebasicfunctionality)

Morereliableandsecure(lesscoderunninginkernelmode?)
MicrokernelSystemStructure

Chapter3Processes
1.Whatisaprocess?Differencebetweenaprocessandprogram.
Process:programbeingexecuted,processmustprogressin
order(Onlyoneprocesshasaccesstotheprocessoratatime)
Programvs.Process:Programcanliveondisk(forexample),
butprocessmustbeinexecution(passivevsactive)
2.Understandwhatisthestack,data,heapandtext.
Text:actualcode
Stack:Containstemporarydata(Functionparameter,return
addresses,localvariables)
Datasection:hasglobalvariables
Heap:Hasdynamicallyallocatedmemory
3.Whatstatescanaprocesscanreside?Whatisnext?
New:Theprocessisbeingcreated

Ready:readytobeassignedtoaprocessor
Running:Instructionsarebeingexecuted
Waiting:processwaitsforsomeeventtooccur
Terminated:finishedexecution1

111

4.Whatisinaprocesscontrolblock?Whyisitnecessary?
Akataskcontrolblock,keepstrackofprocessesinexecution,
eg,state,programcounter,schedulinginfo,contentsofregisters,
memorymanagement,stats,i/oinfo

Necessarybecauseitservesasrepositoryforanyinformationthat
mayvaryfromprocesstoprocess
5.Whatisthedifferencebetweenafork()andexec()andwait()?
fork():startanewprocess.Returns0tochild,positivepidof
childtotheparent,negativeiffailure
exec():executeaprograminthemiddleofaprocess,replace
processmemoryspacewithnewprogram
wait():returnchildpidonsuccess
6.Understandhowmanyprocessesarecreatedwhendoingafork.
Irecommendyouwritingacoupleofprogramsandfindingout
yourself.Whatisthebestwaytotellifanewprocesshasbeen
created?

fork()producesonemoreprocesswhenitiscalled.Ex:
Intmain(){
//oneprocess
fork()
//twoprocesses
fork()
//fourprocesses
fork()
//eightprocesses
}
Ithinkagoodformulais2^nnumberofprocesses,wherenis#of
forks

Bestwaytotellifnewprocesswascreated:
Dopid=fork()
Checkif(pid==0)//0meansthisisachildprocess

7.Whatisathread?Differencebetweenathreadandaprocess.
ThreadSubsetsofaprocess
ProcessIndependent
Atfirst,processissinglethreadofexecution
Runastartingpoint(afunction)inaprogrammultiple
timeswithinthesameprocess
Multipleprogramcountersinaprocesskeeptrackof
threads

8.WhatistheprocessID?

Idgiventoaprocess.Childrenalways>parent
9.Whatisthedifferencebetweenazombieandanorphan?
Zombie:noparentwaiting(parentdoesntcallwait())
Then,parentcontinuesdoingstuffwhilechildrenarealive
Orphan:parentterminateswithoutcallingwait()//parentisdead
10.Sharedmemoryvs.messagepassing
Whenprocessesneedtocommunicatewitheachother,two
options:
Sharedmemory
Bothprocessesaccessthesamememory
Messagepassing
Messagesaddedtoglobalqueuethatbothprocesses
canaccess
Paradigm:producerconsumerproducerprocessmakesinfo
usedbyconsumerprocess

11.Whyisinterprocesscommunicationneeded?Howarepipes
used?
Pipesprovidecommunicationneededsotheycantalktoeach

other,soparentcantalktochildprocesses(usuallyunidirectional)

Namedpipesarebidirectional.Ordinarypipesareunidirectional.

Chapter4.Threading
Threadsaresubsetsofaprocess
Theysharethesameaddressspaceandresourceswithotherthreads

1.MultiCorevsMultiProcessing(?Slide10seemstosaytheyare
same?)
http://superuser.com/questions/214331/whatisthedifferencebetwee
nmulticoreandmultiprocessor

Multicoremultiplecoresincpu,duplicatedcomponentsincpu
Multiprocessingmultiplecpusdoingprocessing
Canhavemulticoreandmultiprocessingsyste

2.Signalhandling(Slide40)
Usedtoprocesssignals(usedinUNIXtonotifyprocessthata
particulareventhasoccured)
Signalgenerated(ERRORS)>Signalsenttoprocess>Signalis
handled(default/userdefined(canoverridedefault))

3.Whenismultithreadingbetterthansinglethreading?Whenisit
not?
ResponsivenessMultithreadingmayallowaprogramtocontinue
evenifpartofitisblocked.Goodforthingslikebrowserinteraction
whileimageisloadedwithanotherthread.
Singlethreadingisbetterwhentheoverheadtocreatingmultiple
threadscostsmorethantheworkperformedbythem.

4.Whatisathreadpoolandwhymightitbeused?(Slide32)
Createanumberofthreadsinpoolthatawaitswork
Slightlyfastertoservicerequestwithexistingthread
Canbind#ofthreadsinapplicationstosizeofpool

5.WhatisAmdahlslaw?
Identifiesperformancegainsfromadditionalcorestoanapplication
withbothserialandparallelcomponents
SSerialportion
NProcessingcores

(Thatis,ifapplicationis75%parallel/25%serial,movingfrom1to2
coresresultsinspeedupof1.6times
)??
Asn>INfinity,speedupapproaches1/S

Chapter5.ProcessSynchronization
1.Whatistheproducerconsumerproblem?(Slide6?)
Producerswritedatatobufferaslongasthereisspace
Consumersreadfrombufferaslongasthereisdata.
Producersdonotwanttobumpintotheconsumer
Goodtohaveabuffertoloadproducersstuffinto,tokeepit
frombeingpausy
2.Whatisaracecondition?(Slide9)
Araceconditionisanundesirablesituationthatoccurswhena
deviceorsystemattemptstoperformtwoormoreoperationsatthe
sametime,butbecauseofthenatureofthedeviceorsystem,the
operationsmustbedoneinthepropersequencetobedone
correctly.(copied)


Araceconditionorracehazardisthebehaviorofanelectronic,
softwareorothersystemwheretheoutputisdependentonthe

sequenceortimingofotheruncontrollableevents.Itbecomesabug
wheneventsdonothappenintheordertheprogrammerintended.

Thetermoriginateswiththeideaoftwosignalsracingeachotherto
influencetheoutputfirst.(copied)

Operationsneedtogoincertainorderforproperoutput,butproblem
ariseswhenmultipleoperationsoccuratsametimeaffectingthe
output.Thetermoriginateswiththeideaoftwosignalsracingeach
othertoinfluencetheoutputfirst.

3.Whatisthecriticalsection?(Slide10,11)

Importantsegmentofcodewhereitischangingcommonvariables,
etc.Whenoneprocessisincriticalsection,othersmaynotbeinit.
???
Fromgoogle:
Inconcurrentprogramming,acriticalsectionisapartofamultiprocess
programthatmaynotbeconcurrentlyexecutedbymorethanoneofthe
program'sprocesses.Inotherwords,itisapieceofaprogramthatrequires
mutualexclusionofaccess.

4.Whatisthesolutiontothecriticalsectionproblem?(Slide13)
Thesethreeconditionsmustbemet:

MutualExclusionIfaprocessisinitscriticalsection,noother
processcanexecutetheirowncriticalsections

Progress:Noprocessisforcedtowaitforanavailableresource
otherwiseveryWasteful.

BoundedWaiting:Noprocesscanwaitforeverforaresourcea
boundmustexistontheamountoftimeotherprocessesareallowed
toentertheircriticalsectionafteroneprocesshasmadearequestto
doso.

5.Differencebetweenapreemptiveandnonpreemptivekernel?

Preemptiveallowspreemption(kernelmodecansuspend
processeswithouttheirconsent.)ofprocesswhenrunning
inkernelmode.Processescanbesuspendedorstopped
involuntarily.
Nonpreemptiverunsuntilexitskernelmode,blocks,or
voluntarilyyieldsCPU.CPUcantforceprocessestoyield.

6.Differencebetweenamutex,semaphoreandspinlock.
Mutualexclusionlock:forcesthreadstowaitforaresourceifit
iscurrentlylocked.acquire()release()forbeforeandaftera
resourceisused
Semaphore:datatype(integer)thatcanonlybeaccessedby
wait()andsignal().wait()meansmatte~dontuseme,signal()

meansImready,or:wait():lockthesemaphore,signal():unlockthe
semaphore

Spinlock:alockwhichcausesathreadtryingtoacquireittosimplywaitina
loop("spin")whilerepeatedlycheckingifthelockisavailable.Sincethethread
remainsactivebutisnotperformingausefultask,theuseofsuchalockisakind
ofbusywaiting.SpinlockoccursinMutexduringacquire()

7.Whatisdeadlockandstarvation?Whatmightcausethis?
Deadlock:2+processeswaitforaneventcausedbyonlyoneofthe
waitingprocesses
Deadlockonlyoccursifandonlyif4conditionsaremet
1. Mutualexclusion:atleastoneresourcemustbeheldina
nonsharablemode.
2. Holdandwait:theremustbeaprocessholdingoneresource
andwaitingforanother
3. Nopreemption:resourcescannotbepreempted.
4. Circularwait:theremustexistasetofprocesses.

LetSandQbetwosemaphoresinitializedto1
P0

P1

wait(S)

wait(Q)

wait(Q)//problem:P0cantdo
//thisuntilP1signal(Q)

wait(S)//problem:P1cantdo
//thisuntilP0signal(s)

...

...

signal(S)

signal(Q)

signal(Q)

signal(S)

Starvation:processcantberemovedfromsemaphorequeue,where
itissuspended.
8.WhatistheReadersandWritersproblem?
Severalconcurrentprocessesshareadataset
Multiplereaderscanreadatsametime(theydontdoupdates)
Writers:canreadand/orwrite
Problem:whattodoiftheprocesseswanttoreadthedataatthe
sametime?
Onlysinglewritercanaccessshareddata
9.WhatistheDiningPhilosophersproblem?
Philosophersonlythinkandeat
Use2chopstickstoeatfrombowl
Howtohavemultiplephilosopherssitattableandbeabletoeatwith
chopsticks(?)
https://www.youtube.com/watch?v=M3CNoX8wetM
10.Whatisamonitorandhowisitused?
Datatype,provideprocesssynchronization.Onlyoneprocessmaybe
activewithinmonitoratatime.So,themonitorhasaqueueof
processes,anddecideswhichoneshouldbeactive(therecanbeonly
one)thewaytosolvethediningphilosophersproblem

Chapter6.Scheduling

1.Whyisschedulingneeded?
YoualwayswanttheCPUtobedoingsomething,sothescheduler
makessurethatalltheresourcescanbeusedarebeingused.
2.Whatcriteriawouldyoubaseschedulingon?
Thereare4criteriastobaseschedulingon:
1)CPUUtilizationkeeptheCPUasbusyasyoucan
2)ThroughputThe#ofprocessesthatcancompletetheir
executioninacertainamountoftimepertimeunit
3)TurnaroundTimeTheamountoftimetheprocesstakesto
execute
4)WaitingtimeTheamountoftimeaprocesshasbeenwaiting
inthereadyqueue
5)ResponsetimeTheamountoftimeittakesfromwhena
requestissubmittedtowhenitisallowedtostart
3.Whataretheschedulingalgorithmscoveredinclass?First
Come,FirstServed,ShortestJobFirst,
First come:firstin
shortestjobfirst:shorterbetter
priority:givenumbertoprocess,highergoesfirst,
roundrobin:eachprocessgets asmallunitofcputime
4.Whymightamultilevelfeedbackqueuebeused?
Processesaresegregatedintoroundrobinorapriority(firstcome
firstserve)queue,themultilevelfeedbackqueuehastheabilityto
moveprocessesbetweenqueues.Forsomereasonifyouwanta
processintheroundrobintohaveahigherpriorityyoucanmoveitto
thepriorityqueue.
5.Whydoweneedrealtimescheduling?

Ataskneedstobedonerightawayanditsnotatthetopofthe
priorityqueuesothereneedstobearealtimeschedulertomoveit
up.
Chapter7.Deadlocks
1.Deadlockcanariseifthesefourconditionsholdsimultaneously.
1.

MutualExclusion:only1processatatimecanusea
resource
2.
holdandwait:aprocessholdingatleastoneresourceis
waitingto acquireadditionalresourcesheldbyotherprocesses
3.
nopreemption:aresourcecanbereleasedonlyvoluntarily
bythe
processholdingit,afterthatprocesshascompleted
itstask
4.
circularwait:thereexistsa
setofwaitingprocesses
suchthatP0iswaitingforaresourceheld byP1,P1iswaiting
foraresourceheldbyP2andsoon

2.Determineifthereisadeadlockgivenaresourceallocation
graph.
3.UsingtheBankersalgorithm,determineifwearegoingtobein
deadlock.
4.UsingtheDetectionalgorithm,determineifweareindeadlock.

StuffTompkinssaidcouldshowuponthe
midterm:
1. Wouldyouwanttoprogrammaticallyturnoffsecureboot?
a. No,ifitseasilyturnedoff,whatsthepointofsecureboot?
2. Processvsthread?
a. Process:handlesoneprogramtypically.Thread:canbeseveral
withinaprogram,usedtosplitworkup.(severalthreadsinaprocess
potentially)
3. Differencesbtwmutexandsemaphore
4. Deadlockcharacterization
5. Whatpieceofsoftwareaddressesbinding?

a. Dispacher