OPERATINGSYSTEMS:DESIGNANDIMPLEMENTATIONTHIRDEDITIONPROBLEMSOLUTIONSANDREWS.TANENBAUMVrijeUniversiteitAmsterdam,TheNetherlandsALBERTS.WOODHULLAmherst,MassachusettsPRENTICEHALLUPPERSADDLERIVER,NJ07458SOLUTIONSTOCHAPTER1PROBLEMS1.Anoperatingsystemmustprovidetheuserswithanextended(i.e.,virtual)machine,anditmustmanagetheI/Odevicesandothersystemresources.2.Inkernelmode,everymachineinstructionisallowed,asisaccesstoalltheI/Odevices.Inusermode,manysensitiveinstructionsareprohibited.Operatingsystemsusethesetwomodestoencapsulateuserprograms.Run-ninguserprogramsinusermodekeepsthemfromdoingI/Oandpreventsthemfrominterferingwitheachotherandwiththekernel.3.MultiprogrammingistherapidswitchingoftheCPUbetweenmultipleprocessesinmemory.ItiscommonlyusedtokeeptheCPUbusywhileoneormoreprocessesaredoingI/O.4.Inputspoolingisthetechniqueofreadinginjobs,forexample,fromcards,ontothedisk,sothatwhenthecurrentlyexecutingprocessesarefinished,therewillbeworkwaitingfortheCPU.Outputspoolingconsistsoffirstcopyingprintablefilestodiskbeforeprintingthem,ratherthanprintingdirectlyastheoutputisgenerated.Inputspoolingonapersonalcomputerisnotverylikely,butoutputspoolingis.5.TheprimereasonformultiprogrammingistogivetheCPUsomethingtodowhilewaitingforI/Otocomplete.IfthereisnoDMA,theCPUisfullyoccu-pieddoingI/O,sothereisnothingtobegained(atleastintermsofCPUutili-zation)bymultiprogramming.NomatterhowmuchI/Oaprogramdoes,theCPUwillbe100percentbusy.Thisofcourseassumesthemajordelayisthewaitwhiledataiscopied.ACPUcoulddootherworkiftheI/Owereslowforotherreasons(arrivingonaserialline,forinstance).6.Secondgenerationcomputersdidnothavethenecessaryhardwaretoprotecttheoperatingsystemfrommalicioususerprograms.7.Choices(a),(c),and(d)shouldberestrictedtokernelmode.8.Personalcomputersystemsarealwaysinteractive,oftenwithonlyasingleuser.Mainframesystemsnearlyalwaysemphasizebatchortimesharingwithmanyusers.Protectionismuchmoreofanissueonmainframesystems,asisefficientuseofallresources.9.Argumentsforclosedsourcearethatthecompanycanvettheprogrammers,establishprogrammingstandards,andenforceadevelopmentandtestingmethodology.Themainargumentsforopensourceisthatmanymorepeoplelookatthecode,sothereisaformofpeerreviewandtheoddsofabugslip-pinginaremuchsmallerwithsomuchmoreinspection.2PROBLEMSOLUTIONSFORCHAPTER110.Thefilewillbeexecuted.11.Itisoftenessentialtohavesomeonewhocandothingsthatarenormallyfor-bidden.Forexample,auserstartsupajobthatgeneratesaninfiniteamountofoutput.Theuserthenlogsoutandgoesonathree-weekvacationtoLon-don.Soonerorlaterthediskwillfillup,andthesuperuserwillhavetomanu-allykilltheprocessandremovetheoutputfile.Manyothersuchexamplesexist.12.Anyfilecaneasilybenamedusingitsabsolutepath.Thusgettingridofworkingdirectoriesandrelativepathswouldonlybeaminorinconvenience.Theotherwayaroundisalsopossible,buttrickier.Inprincipleiftheworkingdirectoryis,say,/home/ast/projects/research/proj1onecouldrefertothepasswordfileas../../../../etc/passwd,butitisveryclumsy.Thiswouldnotbeapracticalwayofworking.13.Theprocesstableisneededtostorethestateofaprocessthatiscurrentlysuspended,eitherreadyorblocked.Itisnotneededinasingleprocesssys-tembecausethesingleprocessisneversuspended.14.Blockspecialfilesconsistofnumberedblocks,eachofwhichcanbereadorwrittenindependentlyofalltheotherones.Itispossibletoseektoanyblockandstartreadingorwriting.Thisisnotpossiblewithcharacterspecialfiles.15.Thereadworksnormally.User2’sdirectoryentrycontainsapointertothei-nodeofthefile,andthereferencecountinthei-nodewasincrementedwhenuser2linkedtoit.Sothereferencecountwillbenonzeroandthefileitselfwillnotberemovedwhenuser1removeshisdirectoryentryforit.Onlywhenalldirectoryentriesforafilehavebeenremovedwillitsi-nodeanddataactuallyvanish.16.No,theyarenotsoessential.Intheabsenceofpipes,program1couldwriteitsoutputtoafileandprogram2couldreadthefile.Whilethisislessefficientthanusingapipebetweenthem,andusesunnecessarydiskspace,inmostcircumstancesitwouldworkadequately.17.Thedisplaycommandandreponseforastereoorcameraissimilartotheshell.Itisagraphicalcommandinterfacetothedevice.18.Windowshasacallspawnthatcreatesanewprocessandstartsaspecificprograminit.Itiseffectivelyacombinationofforkandexec.19.Ifanordinaryusercouldsettherootdirectoryanywhereinthetree,hecouldcreateafileetc/passwdinhishomedirectory,andthenmakethattherootdirectory.Hecouldthenexecutesomecommand,suchassuorloginthatreadsthepasswordfile,andtrickthesystemintousinghispasswordfile,insteadoftherealone.PROBLEMSOLUTIONSFORCHAPTER1320.Thegetpid,getuid,getgid,andgetpgrp,callsjustextractawordfromthepro-cesstableandreturnit.Theywillexecuteveryquickly.Theyareallequallyfast.21.Thesystemcallscancollectivelyuse500millioninstructions/sec.Ifeachcalltakes1000instructions,upto500,000systemcalls/secarepossiblewhileconsumingonlyhalftheCPU.22.No,unlinkremovesanyfile,whetheritbeforaregularfileoraspecialfile.23.Whenauserprogramwritesonafile,thedatadoesnotreallygotothedisk.Itgoestothebuffercache.TheupdateprogramissuesSYNCcallsevery30secondstoforcethedirtyblocksinthecacheontothedisk,inordertolimitthepotentialdamagethatasystemcr