Linux操作系统实验.docx
《Linux操作系统实验.docx》由会员分享,可在线阅读,更多相关《Linux操作系统实验.docx(24页珍藏版)》请在课桌文档上搜索。
1、Project1SystemsProgrammingPractice:TheYalnixShellEducationalObjectives:Studentscometothiscoursewithvariousexperiences.Formanypeoplethisprojectwillbepracticeand/orawarmup.Forothers,itW川bealearningexercise.Regardlessofyourbackground,bytheendofthisproject,wehopethatyouwillcomfortablyandconfidentlybeabl
2、etodothefollowing: Developclear,readable,well-documentedandwell-designedprogramsintheCProgrammingLanguage. DevelopsoftwareintheUnix/Linuxusingtoolssuchasgcc,gdb,andmake. 1.ocateandinterpreting,manpagesapplicabletoapplication-levelsystemprogramming. UsethePOSIX/UnixAPItosystemfunctionstomanageprocess
3、andsessionsaswellasusesignalsandpipesforinter-processcommunication. Understandinghowsynchronizationmightbecomeproblematicinlightofconcurrency. Understandhowtocommunicateandcooperatewithaprojectpartner.ProjectOverviewInthisprojectyouareaskedtoimplementasimplecommand-interpreter,a.k,a.shell,forLinux.T
4、heshellthatyouwillimplement,knownasysh,shouldbesimilartopopularshellssuchasbash,csh1tcsh1zsh,&c,butitisnotrequiredtoimplementasmanyfeaturesasthesecommercial-gradeproducts.Althoughwedontrequireallofthe*,bellsandwhistlesthatareincorporatedintocommercial-gradeproducts,yshshouldhavemuchoftheimportantfun
5、ctionality: Allowtheusertoexecuteoneormoreprograms,fromexecutablefilesonthefile-system,asbackgroundorforegroundjobs. Providejob-control,includingajoblistandtoolsforchangingtheforeground/backgroundstatusofcurrentlyrunningjobsandjobsuspension/continuation/termination. Allowforthepipingofseveraltasksas
6、wellasinputandoutputredirection.Withrespecttotheotherprogrammingassignmentsthissemester,andmanyothersinyourexperience,thisislikelytobeasmallproject,butwewantyoutoapproachitasifitisabiggerandmorecomplexprojectsothatyouarepreparedfortheremainingprojects.Specifically,we,dlikeyoutodothefollowing: Usethe
7、makeutilitytobuildyourproject Useadebuggerinsteadofprint-ad-huntdebuggingwheneverpractical. Produceclean,well-documented,andwell-designedsolutions.SpecificationFormYoursolutionshouldbeanapplicationprograminvokedwithoutcommand-lineparametersorconfigurationfiles,&c.Ifyouwanttobefancyandsupportforareso
8、urcefilesimilartothoseusedwithcommercial-gradeshells,e.g.cshrc,you,reawelcometodothis.But,likecsh,yourshellshouldfunctioncorrectlyinabsenceofthisfile.1.ook-and-FeelThelookandfeelofyshshouldbeSimilartothatofotherUNIXshells,suchasbash,tcsh,csh,&c.Forexample,yourshellsworkloopshouldproduceaprompt,e.g.,
9、ysh,acceptinputfromtheuser,andthenproduceanotherprompt.Messagesshouldbewrittentothescreenasnecessary,andthepromptshouldbedelayedwhenuserinputshouldn,tbeaccepted,asnecessary.Needlesstosay,yourshellshouldtakeappropriateactioninresponsetotheuserSinput.InternalCommandsvs.ExternalProgramsInmostcases,theu
10、ser*sinputwillbeacommandtoexecuteprogramsstoredwithinafilesystem.We,Ilcalltheseexternalprograms.Yourshellshouldallowtheseprogramstoexecutewithstdinand/orstdoutreassignedtoafile.ItshouldallowprogramsI/Otobechainedtogetherusingpipes.Forourpurposes,acollectionofpipedprocessesorasingleprocessexecutedbyi
11、tselffromthecommandlineiscalledajob.Whenexecutingbackgroundsjobs,theshellshouldnotwaitforthejobtofinishbeforeprompting,reading,andprocessingthenextcommand.Whenabackgroundjobfinallyterminatesamessagetothateffectmustbeprinted,bytheshell,totheterminal.Thismessageshouldbeprintedassoonasthejobterminates.
12、ThesyntaxfordoingthiswillbedescribedinthesectionofthisdocumentdescribingtheshellSparser.Yourparsershouldalsosupportseveralinterna!commandsthesecommands,ifissuedbytheuser,shoulddirecttheshelltotakeaparticularactionitselfinsteadofdirectingittoexecuteotherprograms.Thedetailsofthisarediscussedinthesecti
13、ondescribinginternalcommands.Foregroundvs.BackgroundJobsYourshellshouldbecapableofexecutingbothforegroundandbackgroundjobs.Whereasyourshellshouldwaitforforegroundjobstocompletebeforecontinuing,itshouldimmediatelycontinue,prompttheuser,&c,afterplacingajobintothebackground.CommandlinesWhentheuserrespo
14、ndstoaprompt,whattheytypecomposesacommandHnestring.Yourshellshouldstoreeachcommand-linestring,untilthejobisfinishedexecuting.Thisincludesbothbackgroundandsuspendedjobs.Theshellshouldassigneachcommand-linestringanon-negativeintegeridentifier.Thedatastructureusedtostorethejobsshouldallowaccesstoeachel
15、ementusingthisidentifier.Oncetheactionsdirectedbyacommand-linestringarecompleted,yourshellshouldremoveitfromthedatastructure.Identifierscanberecycledifyouchoose.Pleasenotethatthisdatastructureshouldkeeptrackofwholecommandlinestrings,notjustthenamesoftheindividualtasksthatmaycomposethem.Youshouldnotk
16、eeptrackofcommandlinestringsthatcontaininternalcommands,since,bytheirnature,theywillcompletebeforethisinformationcouldbecomeuseful.InternalCommandsThefollowingaretheinternalcommands.Ifaninternalcommandissubmittedbytheuser,theshellshouldtakethedescribedactionsitself.exit:Killallchildprocessesandexity
17、shwithameaningfulreturncode.jobs:Printoutthecommandlinestringsforjobsthatarecurrentlyexecutinginthebackgroundandjobsthatarecurrentlysuspended,aswellastheidentifierassociatedwitheachcommandlinestring.Youmayformattheoutputofthiscommandinwaythatisconvenienttotheuser.Pleaserememberthatjobsitselfisaninte
18、rnalcommandandconsequentlyshouldnotappearintheoutput. echo$status:Printstheexitstatusofthemostrecentforegroundchildprocesstohaveexited.Return0ifnosuchchildhasexisted. fg%:Bringsthejobidentifiedbyintotheforeground.Ifthisjobwaspreviouslystopped,itshouldnowberunning.Yourshellshouldwaitforaforegoundchil
19、dtoterminatebeforereturningacommandpromptortakinganyotheraction. bg%:Executethesuspendedjobidentifiedbyinthebackground. InternalcommandscantakeadvantageofpipedI/O,executeinthebackground,&c,asappropriate.SpecialKeystrokesThroughaninteractionwiththeterminaldriver,certaincombinationsofkeystrokeswillgen
20、eratesignalstoyourshellinsteadofappearingwithinstdin.Yourshellshouldrespondappropriatelytothesesignals. Control-ZgeneratesaSIGSTOP.Thisshouldnotcauseyourshelltobesuspended.Instead,itshouldcauseyourshelltosuspendtheprocessesinthecurrentforegroundjob.Ifthereisnoforegroundjob,itshouldhavenoeffect. Cont
21、rol-CgeneratesaSIGINT.Thisshouldnotkillyourshell.Insteaditshouldcauseyourshelltokilltheprocessesinthecurrentforegroundjob.Ifthereisnoforegroundjob,itshouldhavenoeffect.ParsingUserInput-Overview,DelimitersandSpecialCharactersYourparserforuserinputshouldbecapableofacceptinginputfromtheuserasdescribedi
22、nthissection.Itshouldalsodetectimproperinputfromtheuser.Iftheuserenterssomethingimproper,yourshellshouldproduceameaningfulerrormessage.Justlikecommercial-gradeshells,yourshellshouldacceptinputfromtheuseronelineatatime.Youshouldbeginparsingtheusersinputwhenhe/shehitsenter.Emptycommandlinesshouldbetre
23、atedasno-opsandyieldanewprompt.Blank-spacecharactersshouldbetreatedasdelimiters,butyourshellshouldbeinsensitivetorepeatedblankspaces.Itshouldalsobeinsensitivetoblankspacesatthebeginningorendofthecommandline.Certaincharacters,knownasmeta-characters,havespecialmeaningswithinthecontextofuserinput.These
24、charactersinclude&,Yourshellcanassumethatthesemeta-characterscannotoccurinsidestringsrepresentingprograms,arguments,orfiles.Insteadtheyarereservedforusebytheshell.Thepurposeofmeta-charactersisdiscussedlaterinthissection.ParsingUserInput-InternalCommandsIfthecommandlinematchestheformatofaninternalcom
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Linux 操作系统 实验
链接地址:https://www.desk33.com/p-991003.html