• 54.42 KB
  • 2022-04-22 11:50:10 发布

《unix操作系统设计》英文版习题答案2.pdf

  • 6页
  • 当前文档由用户上传发布,收益归属用户
  1. 1、本文档共5页,可阅读全部内容。
  2. 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
  3. 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
  4. 文档侵权举报电话:19940600175。
'S.6SpectrumALL-IN-ONEJournalforEngineeringStudents,2013CodeNo.:9A05602/R09B.Tech.IIIYearIISemesterRegularExaminationsSet-2April/May-2012SolutionsUNIXINTERNALS(ComputerScienceandEngineering)Time:3HoursMax.Marks:70AnsweranyFIVEQuestionsAllQuestionscarryequalmarks---1.(a)MentionthecharacteristicsoftheUNIXfilesystem.Drawandexplainthesamplefilesystemwithatreestructure.(Unit-I,TopicNo.1.2)(b)Drawandexplaintheblockdiagramforthesystemkernel.(Unit-I,TopicNo.1.5.1)2.Whatarethedifferentscenariosthatthekernelfollowsingetblktoallocateabufferforadiskblock?Explainthemindetail.(Unit-II,TopicNo.2.3)3.(a)Writeshortnotesonthestructureofaregularfile.(Unit-III,TopicNo.3.2)(b)Writeandexplainanalgorithmforallocationofin-coreinodes.(Unit-III,TopicNo.3.1)4.(a)Discussindetailaboutthewritesystemcall.(Unit-IV,TopicNo.4.1)(b)Givebriefdescriptionaboutmountingthefilesystem.(Unit-IV,TopicNo.4.11)5.(a)PresentadetailnoteontheUareaofaprocess.(Unit-V,TopicNo.5.1)(b)Explainindetailabouttheinterruptsandexceptionsofaprocess.(Unit-V,TopicNo.5.1)6.(a)Howcanwechangethesizeofaprocess?Explainitindetail.(Unit-VI,TopicNo.6.7)(b)Describeanimplementationofthekillsystemcall.(Unit-VI,TopicNo.6.2)7.(a)Explainthevarioussystemcallsfortime.(Unit-VII,TopicNo.7.2)(b)Explainhowtocontroltheprocessprioritieswithsuitableexamples.(Unit-VII,TopicNo.7.1)8.(a)Explaintheterminaldriversusingtherawmode.(Unit-VIII,TopicNo.8.3)(b)Writeapseudocodeformultiplexingwindows.(Unit-VIII,TopicNo.8.3)B.Tech.III-YearII-Sem.(JNTU-Anantapur) UnixInternals(April/May-2012,Set-2)JNTU-AnantapurS.7SOLUTIONSTOAPRIL/MAY-2012,SET-2,QPQ1.(a)MentionthecharacteristicsoftheUNIX(b)Explainindetailabouttheinterruptsfilesystem.Drawandexplaintheandexceptionsofaprocess.samplefilesystemwithatreestructure.Answer:April/May-12,Set-2,Q5(b)Answer:April/May-12,Set-2,Q1(a)Ingeneral,aninterruptcanbedefinedasaneventForanswerreferUnit-I,Q3,Topic:FeaturesofUnixthatchangesthesequenceofinstructionsintheexecutionFileSystemandUnixFileStructure.ofaprocessor.Interruptsareclassifiedintotwotypessynchronousandasynchronous.(b)Drawandexplaintheblockdiagramforthesystemkernel.(a)SynchronousInterruptsTheseinterruptsaregeneratedbytheCPUcontrolAnswer:April/May-12,Set-2,Q1(b)unitduringtheexecutionofinstructions.AfterterminatingForanswerreferUnit-I,Q10.theexecutionofaninstruction,thecontrolunitissuestheinterrupts.Duetothis,theyareknownassynchronousQ2.Whatarethedifferentscenariosthattheinterrupts.kernelfollowsingetblktoallocateabufferforadiskblock?Explainthemindetail.(b)AsynchronousInterruptsAnswer:April/May-12,Set-2,Q2TheseinterruptsaregeneratedbyotherhardwaredevicesatvariousinstantsbasedontheCPUclocksignals.ForanswerreferUnit-II,Q3.ManualsofIntelmicroprocessordesignatedtheseQ3.(a)Writeshortnotesonthestructureofainterruptsasexceptionsandinterrupts.regularfile.ExceptionsAnswer:April/May-12,Set-2,Q3(a)Synchronousinterruptsaredesignatedasexceptions.ForanswerreferUnit-III,Q6.Theyaregeneratedeitherbytheerrorsofaprogramorbytheanomalousconditionswhicharehandledbythekernel.(b)WriteandexplainanalgorithmforExceptionscausedbytheprogrammingerrorsarehandledallocationofin-coreinodes.bythekernel.Answer:April/May-12,Set-2,Q3(b)Itgivesasignalwhichiswellknownamongthedeveloperstothecurrentprocess.ExceptionscausedbyForanswerreferUnit-III,Q4.theanomolousconditionsarehandledbythekernelusingQ4.(a)Discussindetailaboutthewritesystemassemblylanguageinstructionslikeintorsysenter.call.Exceptionsareclassifiedinto-processor-detectedAnswer:April/May-12,Set-2,Q4(a)exceptionsandprogrammedexceptions.ForanswerreferUnit-IV,Q1,Topic:write().Processor-detectedExceptionsWhentheCPUcontrolunitraisestheexception,some(b)Givebriefdescriptionaboutmountingvalueofeipregisterissavedinthekernelmodestack.Thisthefilesystem.valueisthebasisfordividingtheprocessor-detectedAnswer:April/May-12,Set-2,Q4(b)exceptionsfurtherintothefollowingthreecategories,ForanswerreferUnit-IV,Q12.(i)FaultsQ5.(a)PresentadetailnoteontheUareaofaFaultsareraisedbythesavedeipvaluewhichrefersprocess.tothelocationoftheinstruction.Theycanbecorrected.Aftercorrection,theprogramisabletoexecutewiththeAnswer:April/May-12,Set-2,Q5(a)samecontinuity.Theinstructionthatcausedthefaultcanberesumedaftertheterminationoftheexceptionhandler.ForanswerreferUnit-V,Q2,Topic:U-area.B.Tech.III-YearII-Sem.(JNTU-Anantapur) S.8SpectrumALL-IN-ONEJournalforEngineeringStudents,2013(ii)TrapsTrapsarereportedsoonaftertheexecutionofthetrappinginstruction.Theeipvalue,whichisthelocationoftheinstructionmustbeexecutedafterthetrappinginstruction.Oncethekernelreturnthecontroltotheprogramtheexecutionfollowsasmoothcontinuity.(iii)AbortsAbortsareusedtoreportseriouserrors.Theseerrorsriskthecontrolunit.Thestoragelocationoftheinstructionintheeipregisterthatraisestheexceptionisdifficult.Thecontrolunitsendsanemergencysignalthatswitchesthecontroltotherelevantabortexceptionhandler.Thishandlerforcefullyterminatestheprocessthathasbeenaffected.ProgrammedExceptionsProgrammedexceptionsareraisedupontherequestoftheprogrammer.Theinstructions,intorint3triggerthem,whensomeconditionthathasbeencheckedisfalsethenthe“into”and“bound”instructionsraisetheseexceptions.Controlunithandlesprogrammedexceptionsintheformoftrapswhicharealsoknownassoftwareinterrupts.InterruptsInterruptsarecausedbytheintervaltimersandI/Odevices.Theyareclassifiedintotwotypes-maskableinterruptsandnon-maskableinterrupts.(a)MaskableInterruptsTheseinterruptsarecausedbytheinterruptrequests(IRQs)oftheI/Odevices.(b)Non-maskableInterruptsTheseinterruptsaregeneratedbysomecriticaleventslikehardwarefailures.TheyarefoundbyCPU.Q6.(a)Howcanwechangethesizeofaprocess?Explainitindetail.Answer:April/May-12,Set-2,Q6(a)ForanswerreferUnit-VI,Q18.(b)Describeanimplementationofthekillsystemcall.Answer:April/May-12,Set-2,Q6(b)KillandRaiseSystemCallsTheprocessescommunicatewitheachotherbysendingsignals.Thekillandraisesystemcallsareusedtosendsignalsbetweenprocesses.Thekillsystemcallsendsasignaltoaprocessorprocessgroups.Theraisesystemcallisusedbyaprocesstosendasignaltoitself.Syntax#include#includeintkill(pid_tpid,intsig_no);intraise(intsig_no);Boththekillandtheraisesystemcallsreturns0onsuccessand–1onerror.B.Tech.III-YearII-Sem.(JNTU-Anantapur) UnixInternals(April/May-2012,Set-2)JNTU-AnantapurS.9Heretheargumentsig_noisthesignalnumberofasignaltobesenttooneormoreprocessesindicatedbypid.TheargumentpidtokillindicatestheprocessIDoftherecipient.Itisinterpretedasgiveninthetablebelow,pidValueMeaningpid>0Sendsthesignalsig_notoaprocesswithprocessIDindicatedbypid.pid==0Sendsthesignalsig_notoallprocesseswhoseprocessgroupIDmatcheswiththatofthecallingprocess.pid<0Sendsthesignalsig_notoallprocesseswhoseprocessgroupIDmatcheswithabsolutevalueofpidandtoallprocessesforwhichthecallingprocesshaspermissiontosendthesignal.pid==–1UnderUnixsystem,sendsthesignalsig_notoallprocesseswhoserealuserIDequalstheeffectiveuserIDofthecallingprocess.IftheeffectiveuserIDofthecallingprocessisthesuperuseruserIDthenthissignalissenttoalltheprocessesinthesystemexceptprocesseswithpid0and1.Inthislattercase.Thekernelcallskilltoterminateallprocesseswhenthesystemisshuttingdown.UnderPOSIX1.Thebehaviourofkillwhenpid=–1isnotspecified.Foraprocesstosendasignaltoanotherprocessitmusthavepermissiontodoso.Asuperuserhasprivilegestosendasignaltoanyprocess.ForotherprocessestosendsignalstheyshouldberelatedtoeachothersuchthattherealoreffectiveuserIDofboththesenderandtherecipientmustbeequal.IfthesignaltobesentisSIGCONTthenaprocesscansendittoalltheprocesseswhoarethememberofthesamesessionthissignalhelpsintestingthepermissions.UnderPOSIX.1system,asignalwithvalue0iscalledanullsignal.Ifakilliscalledwithanullsignalthennosignalsentinsteadkilldoesthenormalerrorchecking.Itisusedtocheckwhetheraspecificprocessstillexists.Inthiscasekillreturns–1ifthatprocessdoesnotexistandsettheerrnotoESRCH.HoweverunderUnixsystemprocessIDsarerecycledaftersomeamountoftime,sowhenkillreturnsthataprocessexistitdoesnotmeanthatitistheprocessthatyouthinkitis.Ifthekillsendsasignaltothecallingprocessitselfandifthesignalisnotblocked,eithersig_noorsomeothersignalispending,thenunblockedsignalissenttotheprocessbeforekillreturns.#include#includemain(){intpida,pidb;pida=fork();if(pida==0){while(1){printf(“pidaisalive”);sleep(1);}}pidb=fork();if(pidb==0){while(1)B.Tech.III-YearII-Sem.(JNTU-Anantapur) S.10SpectrumALL-IN-ONEJournalforEngineeringStudents,2013{printf(“pidbisalive”);sleep(1);kill(pida,SIGINT);/*killprocesspida*/raise(SIGINT);/*killitselfi.e.,pidb*/}}}Q7.(a)Explainthevarioussystemcallsfortime.Answer:April/May-12,Set-2,Q7(a)ForanswerreferUnit-VII,Q6.(b)Explainhowtocontroltheprocessprioritieswithsuitableexamples.Answer:April/May-12,Set-2,Q7(b)ControllingProcessPrioritiesLinuxholdstwoprioritynumbersforeachprocess.Forinstance,if“ps-l”isrunthentwofields“PRI”and“NI”areobtained.ThePRIfieldsgivestheoriginalprocessprioritywhichiscomputeddynamicallywiththeoperatingsystem.TheoperatingsystemconsidersNInumberforcomputingandupdatingthePRInumberthesuperusercansetthisnumbertohaveaneffectontheoriginalPRI./bin/niceutilitycanbeusedtochangetheNInumberaftertheprocessinitiation,“renice”canbeusedforchangingtheexecutionpriority.Thescenariosforchangingtheprocessprioritiesisasfollows,1.UsingNiceProcessprioritycanbereducedbyusingniceor/bin/niceutility.Theauthorityofincreasingtheprocesspriorityrestswiththesuperuseronly.Processpriorityrangesfrom–20to19.Here,–20isthehighestpriorityand19isthelowest.Thisisbecause,inprocesspriority,loweristhenumberhigherwillbethepriority.Beforesettingtheprocesspriorityitmustbedeterminedwhetherthe“nice”hastoberunfromitsbuilt-inversionorfromthe/bin/niceutility.Thisdeterminationisnecessarybecausethesetwoversionsvaryfromeachotherconsiderthefollowingexample.Torunaperlscript/tmp/foo.p1withpriority18withshellversionofnicecommand,givethecommandinthefollowingmanner,nice+18/tmp/foo.p1Thecommandforthe/bin/niceversionforthesamescriptandprioritywouldbe./bin/nice-18/tmp/foo.p1Toincreasethepriority-8,thesuperuserhastogivethefollowingcommands,/bin/nice-8/tmp/foo.p1/bin/nice-8/tmp/foo.p1Ifusageoftheabovecommandsbecomesdifficultthen“since”utilitycanbeusedforsettingthepriority“renice”utilitycanbeusedalongwiththisutilityrunPS-1toverifywhetherthepriorityhasbeenchangedornot.RunProcessinForegroundorinBackgroundIfaprocessrunninginforegroundconsumeslotoftimethenitcanbemadetoruninthebackgroundusingampersand(&)attheendofthecommandline,considerthefollowingexamples.Toknowtheamountofspaceusedbythefilesusethefollowingcommandandrunitinbackground,du>/tmp/du.out&Thiscommanddirectstheoutputtothefile“/tmp/du.out”andpreventsinterruptingtheotheroperationcurrentlyinprocess.B.Tech.III-YearII-Sem.(JNTU-Anantapur) UnixInternals(April/May-2012,Set-2)JNTU-AnantapurS.11Q8.(a)Explaintheterminaldriversusingtherawmode.Answer:April/May-12,Set-2,Q8(a)ForanswerreferUnit-VIII,Q15.(b)Writeapseudocodeformultiplexingwindows.Answer:April/May-12,Set-2,Q8(b)PseudocodeforMultiplexingWindowsfor(;;){select(input);readinputline;switch(linewithinput){casephysical-tty:if(controlcommand){openapseudo-ttywhichisfree;forknewprocessif(itisparent){pushamsgdisciplineonmpx;continue;}closetheunwantedfiledescriptors;opentheothermembersofpseudo-ttypair,getstdin,stdout,stderr;pushttylinediscipline;execshell;}demultiplexthedatawhichisreadfromphysical-tty,removetheheadersandthenwritetoarelevantpty;continue;caselogical_tty;encodeheaderbyspecifyingthepurposeofwindowdata;Nowwriteheaderanddatatophysical-tty;continue;}}B.Tech.III-YearII-Sem.(JNTU-Anantapur)'