turnedtotheinterruptedcontextandinstruction.Atrapisasoftware-generatedinterrup匕AninterruptcanbvusvdtosignalthecoiTipJctk*nofan[/Otoobviatetheneedfnrdu\icypoiling.Atrapcanbeusedtocalloperatingsystemroutinesortocatcharithmeticerrors.
2.5Whichofthefollowinginstructionsshouldbeprivileged?
a.Setvalueoftimer.
b.Readtheclock.
c.Clearmemory.
d.Turnoffinterrupts.
e.Switchfromusertomonitormode.
Answer:
Thefollowinginstructionsshouldbeprivileged:
a.Setvalueoftimer.
b.Clearmemory.
c.Turnoffinterrupta
cLSwitchfromusertomonitormode.
2.8Protectingtheoperatingsystemiscrucialtoensuringthatthecomputersystemoperatescorrectly.Provisionofthisprotectionisthereasonbehinddual-modeoperation,memoryprotection,andthetimer.Toallowmaximumflexibility,however,wewouldalsoliketoplaceminimalconstraintsontheuser.
Thefollowingisalistofoperationsthat
ofinstructionsthatmustbeprotected?
a.Changetousermode.
b.Changetomonitormode.
c.Readfrommonitormemory.
d.Writeintomonitormemory.
e.Fetchaninstructionfrommonitormemory.
f.Turnontimerinterrupt.
g.Turnofftimerinterrupt.
AnswenTheminimalsetofinstructionsthatmustbeprotectedare:
b.
c.
Readfrommonitormemory*
Writeintomonitormemorv.
*
Turnofftimerinterrupt.
3.6Listfiveservicesprovidedbyanoperatingsystem.Explainhoweachprovidesconveniencetotheusers.Explainalsoinwhichcasesitwouldbeimpossibleforuser-level
programstoprovidetheseservices.
Answer:
Programexecution.Theoperatingsystemloadsthecontents(orsections)ofafileintomemoryandbeginsitsexecution.Auser-levelpm呂ramcouldnotbetrustedtoproperlyallocateCPUtime.
I/O'operations.Disks,tapes,seriallines^andotherdevicesmustbecommunicatedwithata\erylowlevel.Theuserneedonlyspecifythedeviceandtheoperationtoperformonit,whilethesystemconvertsthatrequestintodevice-orcontroller-specificcommands.User-levelprogramscannotbetrustedtoonlyaccessdevicestheyshouldhaveaccesstonndtoonlyaccessthemwhentheyartotherwiseunused.
File-systemmanipulation.Therearvmanydetailsinfilecreation,deletion,alkKation,andnamingthatusersshouldnothavetoperform.Blocksofdiskspact?
areusedbyfilesandmustbetracked.Deletingafilerequiresremovingthenamefileinformationandfreeingthe说[locatedbk>cks.[Protectionsmustalsobecheckedtoassureprtiperfileaccess.Userprt^gramscouldneitherensureadherencetctprotectionmethexJsnorbetrustedtoallocateonlyfreeblocksanddeallocateblocksonfiledeletion.
Communications.Messagepassingbetweensystemsrequiresmessagesbeturnedintopacketsofinformation,senttothenetworkcontnUlei;transmittedacrossacommunicationsmedium,andreassembledbythedestinationsystem.Packetorderinganddatacorrectionmusttakeplace.Again,userprogramsmightnotcoordinateaccesstothenetworkdevice,ortheymightreevi^Tpacketsdestinedforotherprocesses.
•Errordetection.Errordetectionoccursatboththehardwareandsofirwarelevels.Atthehardwarele\-el,alldatatransfersmustbeinspectedtoensurethatdatahavenotbeenc(>rruptedintransitAUdataonmediamustbicheckedtobesuretheyhavenotchangedsincetheywerewrittentothemedia.Atthesoftwarelevel,mediamustbecheckedfordataconsistency;forinstance,dothenumberofallt>catedandunallocatedblocksofstoragematchthetotalnumberonthedevice.There,errorsarefrequentlyprexzess-independent(forinstance,thecorruptionofdataonadisk),sotheremustbeaglobalprogram(ttiEoperatingsystem)thathandlesalltype吕oferrors.Also,byhavingerrorsprocessedbytheoperatingsystem,processesneednotcontaincodetocatchandcorrectallthEerrorspossibleonasystEm.
3.7Whatisthepurposeofsystemcalls?
AnswerSystemualls(j1U>wuser-lewlliirequesticesuftl咤uperdtingsv;»-
tem.
3.10Whatisthepurposeofsystemprograms?
jVnswcr:
Evstemprogramscanbethoughtofbundlcz^ufusefulsystctuoils.Tbev
providebasicfuncticrahtytousersandsousersdenotneedtowritetheirownprogramstosol、忙commonproblems.
4.1MS-DOSprovidednomeansofconcurrentprocessing.Discussthreemajorcomplicationsthatconcurrentprocessingaddstoanoperatingsystem.
Answer:
Amethodoftimesharingmustbeimplementedtoalloweachofseveralprocessestohaveaccesstothesysten'i.ThismethodinxoJvcsthepromptionofprocessesthatdonotvoluntarilygiA-euptheCPU(byusingasystemcal],forinstance)Processesandsystemresourcesmusthaveprotectionsandmustbeprciteck?
dfrtiTneachotherAnygivenprocessmustbelimitedintheamountofmemoryitcanuseandtheoperationsitcanperformondeviceslikedisks.
Thecorrectproducer—consumeralgorithminSection4.4allowsonlyn-1bufferstobe
Caremustbetakeninthekerneltopre\entdeadkxzksbetweenprocesse鬲soprcicessesaren'twaitingforeachother'sallcxatedrest>urces.
4.6
fullatanyonetime.Modifythealgorithmtoallowallbufferstobeutilizedfully.
AnswerNoanswer.
5.1Providetwoprogrammingexamplesofmultithreadinggivingimproveperformaneeover
asingle-threadedsolution.
Answer
(1)Aserverthatserviceseachrequestinaseparatethread.
(2)Aparal*lelizedapplicationsuchasmatrixmultiplicationwheredifferentpartsofthematrixmaybeworkedoninparallel.(3)AninteractiveGUIprogramsuchasadibuggerwhereathreadisusedtomonitoruserinput,anotherthreadrepresentstherunningflppHcation,andathirdthreadmonitorsperformance.
5.3Whataretwodifferencesbetweenuser-levelthreadsandkernel-levelthreads?
Under
whatcircumstancesisonetypebetterthantheother?
r■
AnswerContextswitchingbetweenusertlireadsisquitesimilartGswitchingbetweenkernelthreads,althoughitis