+第三版++答桉.docx
《+第三版++答桉.docx》由会员分享,可在线阅读,更多相关《+第三版++答桉.docx(35页珍藏版)》请在冰豆网上搜索。
+第三版++答桉
SOLUTIONSTOCHAPTER1PROBLEMS
1.Anoperatingsystemmustprovidetheuserswithanextended(i.e.,virtual)machine,anditmustmanagetheI/Odevicesandothersystemresources.
2.MultiprogrammingistherapidswitchingoftheCPUbetweenmultipleprocessesinmemory.ItiscommonlyusedtokeeptheCPUbusywhileoneormoreprocessesaredoingI/O.
3.Inputspoolingisthetechniqueofreadinginjobs,forexample,fromcards,ontothedisk,sothatwhenthecurrentlyexecutingprocessesarefinished,therewillbeworkwaitingfortheCPU.Outputspoolingconsistsoffirstcopyingprintablefilestodiskbeforeprintingthem,ratherthanprintingdirectlyastheoutputisgenerated.
Acronymforsimultaneousperipheraloperationson-line,spoolingreferstoputtingjobsinabuffer,aspecialareainmemoryoronadiskwhereadevicecanaccessthemwhenitisready.
Inputspoolingonapersonalcomputerisnotverylikely,butoutputspoolingis.
4.TheprimereasonformultiprogrammingistogivetheCPUsomethingtodowhilewaitingforI/Otocomplete.IfthereisnoDMA,theCPUisfullyoccupieddoingI/O,sothereisnothingtobegained(atleastintermsofCPUutilization)bymultiprogramming.NomatterhowmuchI/Oaprogramdoes,theCPUwillbe100percentbusy.Thisofcourseassumesthemajordelayisthewaitwhiledataarecopied.ACPUcoulddootherworkiftheI/Owereslowforotherreasons(arrivingonaserialline,forinstance).
5.Secondgenerationcomputersdidnothavethenecessaryhardwaretoprotecttheoperatingsystemfrommalicioususerprograms.
6.Itisstillalive.Forexample,IntelmakesPentiumI,II,andIII,and4CPUswithavarietyofdifferentpropertiesincludingspeedandpowerconsumption.Allofthesemachinesarearchitecturallycompatible.Theydifferonlyinpriceandperformance,whichistheessenceofthefamilyidea.
Producememorybank
7.A25×80charactermonochrometextscreenrequiresa2000-bytebuffer.The1024×768pixel24-bitcolorbitmaprequires2,359,296bytes.In1980thesetwooptionswouldhavecost$10and$11,520,respectively.Forcurrentprices,checkonhowmuchRAMcurrentlycosts,probablylessthan$1/MB.
8.Choices(a),(c),and(d)shouldberestrictedtokernelmode.
9.Personalcomputersystemsarealwaysinteractive,oftenwithonlyasingleuser.Mainframesystemsnearlyalwaysemphasizebatchortimesharingwithmanyusers.Protectionismuchmoreofanissueonmainframesystems,asisefficientuseofallresources.
10.Everynanosecondoneinstructionemergesfromthepipeline.Thismeansthemachineisexecuting1billioninstructionspersecond.Itdoesnotmatteratallhowmanystagesthepipelinehas.A10-stagepipelinewith1nsecperstagewouldalsoexecute1billioninstructionspersecond.Allthatmattersishowoftenafinishedinstructionspopsouttheendofthepipeline.
11.Themanuscriptcontains80×50×700=2.8millioncharacters.Thisis,ofcourse,impossibletofitintotheregistersofanycurrentlyavailableCPUandistoobigfora1-MBcache,butifsuchhardwarewereavailable,themanuscriptcouldbescannedin2.8msecfromtheregistersor5.8msecfromthecache.Thereareapproximately27001024-byteblocksofdata,soscanningfromthediskwouldrequireabout27seconds,andfromtape2minutes7seconds.Ofcourse,thesetimesarejusttoreadthedata.Processingandrewritingthedatawouldincreasethetime.
12.Logically,itdoesnotmatterifthelimitregisterusesavirtualaddressoraphysicaladdress.However,theperformanceoftheformerisbetter.Ifvirtualaddressesareused,theadditionofthevirtualaddressandthebaseregistercanstartsimultaneouslywiththecomparisonandthencanruninparallel.Ifphysicaladdressesareused,thecomparisoncannotstartuntiltheadditioniscomplete,increasingtheaccesstime.
13.Maybe.Ifthecallergetscontrolbackandimmediatelyoverwritesthedata,whenthewritefinallyoccurs,thewrongdatawillbewritten.However,ifthedriverfirstcopiesthedatatoaprivatebufferbeforereturning,thenthecallercanbeallowedtocontinueimmediately.Anotherpossibilityistoallowthecallertocontinueandgiveitasignalwhenthebuffermaybereused,butthisistrickyanderrorprone.
14.Atrapiscausedbytheprogramandissynchronouswithit.Iftheprogramisrunagainandagain,thetrapwillalwaysoccuratexactlythesamepositionintheinstructionstream.Aninterruptiscausedbyanexternaleventanditstimingisnotreproducible.
15.Base=40,000andlimit=10,000.Anansweroflimit=50,000isincorrectforthewaythesystemwasdescribedinthisbook.Itcouldhavebeenimplementedthatway,butdoingsowouldhaverequiredwaitinguntiltheaddress+basecalculationwascompletedbeforestartingthelimitcheck,thusslowingdownthecomputer.
16.Theprocesstableisneededtostorethestateofaprocessthatiscurrentlysuspended,eitherreadyorblocked.Itisnotneededinasingleprocesssystembecausethesingleprocessisneversuspended.
17.Mountingafilesystemmakesanyfilesalreadyinthemountpointdirectoryinaccessible,somountpointsarenormallyempty.However,asystemadministratormightwanttocopysomeofthemostimportantfilesnormallylocatedinthemounteddirectorytothemountpointsotheycouldbefoundintheirnormalpathinanemergencywhenthemounteddevicewasbeingcheckedorrepaired
18.Forkcanfailiftherearenofreeslotsleftintheprocesstable(andpossiblyifthereisnomemoryorswapspaceleft).Execcanfailifthefilenamegivendoesnotexistorisnotavalidexecutablefile.Unlinkcanfailifthefiletobeunlinkeddoesnotexistorthecallingprocessdoesnothavetheauthoritytounlinkit.
19.Ifthecallfails,forexamplebecausefdisincorrect,itcanreturn−1.Itcanalsofailbecausethediskisfullanditisnotpossibletowritethenumberofbytesrequested.Onacorrecttermination,italwaysreturnsnbytes.
20.Itcontainsthebytes:
1,5,9,2.
21.Blockspecialfilesconsistofnumberedblocks,eachofwhichcanbereadorwrittenindependentlyofalltheotherones.Itispossibletoseektoanyblockandstartreadingorwriting.Thisisnotpossiblewithcharacterspecialfiles.
22.Systemcallsdonotreallyhavenames,otherthaninadocumentationsense.Whenthelibraryprocedurereadtrapstothekernel,itputsthenumberofthesystemcallinaregisteroronthestack.Thisnumberisusedtoindexintoatable.Thereisreallynonameusedanywhere.Ontheotherhand,thenameofthelibraryprocedureisveryimportant,sincethatiswhatappearsintheprogram.
23.Yesitcan,especiallyifthekernelisamessage-passingsystem.
24.Asfarasprogramlogicisconcerneditdoesnotmatterwhetheracalltoalibraryprocedureresultsinasystemcall.Butifperformanceisanissue,ifataskcanbeaccomplishedwithoutasystemcalltheprogramwillrunfaster.Everysystemcallinvolvesoverheadtimeinswitchingfromtheusercontexttothekernelcontext.Furthermore,onamultiusersystemtheoperatingsystemmayscheduleanotherprocesstorunwhenasystemcallcompletes,furtherslowingtheprogressinrealtimeofacallingprocess.
25.SeveralUNIXcallshavenocounterpartintheWin32API:
Link:
aWin32programcannotrefertoafilebyanalternatenameorseeitinmorethanonedirectory.Also,attemptingtocreatealinkisaconvenientwaytotestforandcreatealockonafile.Mountandumount:
aWindowsprogramcannotmakeassumptionsaboutstandardpathnamesbecauseonsystemswithmultiplediskdrivesthedrivenamepartofthepathmaybedifferent.Chmod:
Windowsprogrammershavetoassumethateveryusercanaccesseveryfile.Kill:
Windowsprogrammerscannotkillamisbehavingprogramthatisnotcooperating.
26.Theconversionsarestraightforward:
(a)Amicroyearis10-6×365×24×3600=31.536sec.
(b)1000metersor1km.
(c)Thereare240bytes,whichis1,099,511,627,776bytes.
(d)Itis6×1024kg.
SOLUTIONSTOCHAPTER2PROBLEMS
1.Thetransitionfromblockedtorunningisconceivable.SupposethataprocessisblockedonI/OandtheI/Ofinishes.IftheCPUisotherwiseidle,theprocesscouldgodirectlyfromblockedtorunning.Theothermissingtransition,fromreadytoblocked,isimpossible.AreadyprocesscannotdoI/Ooranythingelsethatmightblockit.Onlyarunningprocesscanblock.
2.Youcouldhavearegistercontainingapointertothecurrentprocesstableentry.WhenI/Ocompleted,theCPUwouldstorethecurrentmachinestateinthecurrentprocesstableentry.Thenitwouldgototheinterruptvectorfor
theinterruptingdeviceandfetchapointertoanotherprocesstableentry(theserviceprocedure).Thisprocesswouldthenbestartedup.
3.Generally,high-levellanguagesdonotallowonethekindofaccesstoCPUhardwarethatisrequired.Forinstance,aninterrupthandlermayberequiredtoenableanddisabletheinterruptservicingaparticulardevice,ortomanipulatedatawithinaprocess’stackarea.Also,interruptserviceroutinesmustexecuteasrapidlyaspossible.
4.Thereareseveralreasonsforusingaseparatestackforthekernel.Twoofthemareasfollows.First,youdonotwanttheoperatingsystemtocrashbecauseapoorlywrittenuserprogramdoesnotallowforenoughstackspace.Second,ifthekernelleavesstackdatainauserprogram’smemoryspaceuponreturnfromasystemcall,amalicioususermightbeabletousethisdatatofindoutinformationaboutotherprocesses.
5.Itwouldbedifficult,ifnotimpossible,tokeepthefilesystemconsistent.Supposethataclientprocesssendsarequesttoserverprocess1toupdateafile.Thisprocess