大家早点休息吧早安早安早安早安早安早安我和你一起玩好好好今天今天我們是在第四個星期今天我們要結束我們要進去英國的英國的英國的英國的所以今天我們會說今天我們會說你知道有三個很重要的通訊Exact, Exit, Exit, ExitWaitAnd I think it's going to be a sprintThe fork is actually a little more complicated than theseSo I think we can get through this nowBut again, as usual, we will go at the speed of comprehensionSo...alrightCouple announcements as usualAssignment zero is kind of in gripsAnd little bristlesSo now I'm going to put up some questions about the codeFor you guys to go throughAnd then, you know, begin next weekThere's a few more steps, but there's really not that muchIt's really just for meYou guys, if you've built a kernel, you've done a lot of what we want you to do alreadyI do want you guys to kind of get into the sourceAnd start poking aroundSo that's going to be it Lecture video is onlineI'm working on itI'm excited about doing itThey should be online at some pointSo if you guys miss classOr if you know you just want to watch againOr if there's parts that you want to reviewYou can do thatAnd I'm hoping to get it set up to the slidesTo the next door to the videoSo you guys can kind of cater along to the slidesSo you're going to relive the fullest yearI'm going to do it like a couple of times a dayAll right, soAs far as the slides, I got some feedback from somebodySo does anyone try to look at the slides online?Does anyone have a hard time with the images in the slide?Anybody using Internet ExplorerOkaySo this is running on Firefox right nowSo you need a browserThe images are SPGsYou need a browser that supports SPGsAnd as I put it, most decent browsers doSupport is kind of lagging in certain placesInternet ExplorerBut anywayIf you're really struggling with thisSo many kind of viewsWhat do you use?Oh, SafariMaybe tryI'll look into itYou might end up plugging into something like thatBut I'm using SPG for the classIt's too late to go backSo an SPG is kind of semi-newAs in 2009 or somethingSo apparently this hasn't made it to Redmond yetBut anyway, maybe hasn't made it toWhere is Apple?CupertinoAnywayOkaySo last time we talked about 4We did a little bit of pipesSo you see why some of the forks and antics are usefulSo questions about WednesdayAnd what are the linksAnd what are the linksAnd what are the linksAnd where can I find a noteAnd what are the linksSo I sent a link to itAre you getting emails from the client?YesYes, so the link is in thereAnd the website will eventuallyHave links to other things on the buttonBut for now you have to put down those linksAny other questionsWe'll go over to the clientAll right, so last time we talked aboutFilementsWe talked about 4We did a little bit of pipesJust so you seeWhy some of the forks and antics are useful我們現在要進一步你們有機會考慮一下你們有什麼想法有什麼想法有什麼問題你們知道它正在發生你們知道它正在發生我正在在後面的房間可能是我最愛的一堆人OK沒有問題我們來考慮一下我們開始在這裡你的名字JP好我可以寫一句嗎Anderson幫你寫2 plus是同一個得分嗎對你們想寫他們是小孩有4個得分找個目標可能會被對越多的数據很好問題是這個為什麼我們要這樣做?為什麼我們有這三個等級的方式?我們繼續走,這是什麼?這是什麼?這是什麼?為什麼我們要這個等級的方式?為什麼我們要把資料分配在這兩個或是三個不同的部分?你想想看嗎?沒有,我不是說過為什麼?因為我們要做得更快更快?所以這個方式會更快嗎?為什麼?因為每次我用資料分配我都要把資料分配在不同部分的部分用資料分配OK,OK現在你把資料分配在一個好的方式然後把資料分配在那裡對那怎麼辦?那什麼是資料分配?就是資料分配在一個好的方式資料分配在哪一個?資料分配在一個好的方式對,那是什麼?我們把資料分配在不同部分的部分所以籌款別人不需要分配OK,但那五個圖像為何必要分配?因為它能在哪個部分的部分為什麼我把資料分配在那種部分?嗯Yes rightBecause the differentThe different informationIn the different cases of the fileThe different file handlesFile handlingIt can be shared differently with different semanticsRightSo file handles store the offsetWhich means that after forwardThe offset is shared between a parent and a childRightFile objects store a lot of other file informationBut that information is usually notYou know it is shared by everybody who has the file openLike the data in the fileWhich does block the ideas and that like that對嗎但在把最後的解釋成為自己的小物體和其他資訊我可以讓它與其他相關的相關相關如果我有資訊與其他資訊與其他資訊與其他資訊與其他資訊與其他資訊與其他資訊與其他資訊與其他資訊與其他資訊與其他資訊與其他資訊與其他資訊我還不確定這個資訊會令更多東西更多東西但做了很多相關資訊與其他資訊與其他資訊與其他資訊與其他資訊為何我會把資訊告訴你還有一個人已經告訴我為什麼我還想把認識的資訊有人告訴我有一個是一個交易對5VC交易我需要想找一位跟孩子交易跟他們交易But what my business is, it's the way they do it, I do this by copying the file tablesso they have the same file offsets into files that are open alright, there's no requirementSo, let's say that the childcare process, does not want to share an off物��But wants to open the same files what do I need to doRight, I need to close the file descriptor that refers to that fileBut then I just open the file againI get my own, I get a new file descriptorand I get a new file handled that's positive to me.So that's how if I'm a child and I'm not interested in sharing information,I can do that.All right, create a new process.It's easy, come on. Everybody together.Fort, all right.Fort creates a new process that is what?Fort creates a new process that is what?Identical to what?The process is called for.What's one notable possible exception to this rulethat we discussed in class?Freads, because working with threads,I don't think so.All right, following code.Who wants to,let's see,Let's go over here somewhere.Following code,who is the parent and who is the child?The child in your ULM.Yeah,that's what I thought.What's pipe?IPC mechanism.TIP should be allowed.IPC mechanism,right?but tell me more about that.He wants to know more about that.Right,so it's used to create a chain andcommunicating process,but what is it?Is it a file?Yeah,that's a good idea.It's a file like option,right?It's got a read-on-land and a write-on-land.You get a different file script for each.Any data that you write in the write-on-landappears on the read-on-land.And why are pipes useful?We've definitely covered that one.Anybody?It's a big yawn.It's a big yawn.No,no.IPC communication mechanism.And it allows us to establish a chain ofcommunicating process.OK,any other questions?Here you go.Questions,dots.OK,so we talked about fork.but it's forked enoughSo what would the world look like if I just had forked?I start so remember we said that the operating system is thoughtful for setting up the in-it processAnd then if I just had forked, what would the system look like?Well copies of what?InitSo this is not interestingAlternatively, I thought about this a little bitWell you could write your codeYou could write all the code that you would ever want to run on the system in one huge functionWith all these different branches based on whether or not you were the parent or notSo it was like if I'm the parent, run the bash codeAll the bash sort of looks like a new blockAnd if I'm the child, I just kind of paste all the Firefox codeSo that would beWhat?Not as easy way of saying itThat would not be a smart ideaThat would make your system difficult to maintain at the minimumSo I need a way to change a processI need to provide a way for processes to changeTo grow, to develop, to realize their full potentialThe system call that doesn'tIs called or the failure system callsBecause if you look at exactly, it's actually like sixI don't know if these are implemented by the C libraryActually by the kernel, but there are sometimes multiple different versions of exactThere's exact V, there's exact VE, there's exact VCEAnd they all do slightly different thingsThey have slightly different semantics of how they set up the environment and other thingsBut the one thing they all do-doIs allow me to run a new processSomeone have a question?So the exact loads information about the new processAnd that file is required to essentially provide all the informationThat's required to create this new processAnd most of that information is about how to set up the memory of the new processHow to set up the address spaceBut it also includes information about things likeWhat libraries might I want to load and the entry pointSo after the operation sets up the address spaceTo start the process running in its new lifeIt needs to know what's the first instructionWhere's the location of the first instruction in the fileThat the thread should start to executeSo linux and other units like systems use something called elfAnd elf is not an extensionIf you guys have used linux or linux, you've noticed thatUnlike windows, there's not typically a fileExecutable files don't have extensionsSo when you run bash, it's not bash.exeBut there's information in that fileThat identifies it as an elf format fileAnd when you load it, that file has informationAbout what to do when you try to run bashHow to set up the address spaceSo let's look at thisYou guys, I'm sure, have these tools in your virtual machineIf you don't, they're easy to installSo one tip for people that haven't used Ubuntu beforeIf you run a commandIf you want to know how to install a commandYou can try and it's not installed on any systemYou can run it and the system will actually give youThe command necessary to install that commandSo if you're missing something, you type firefoxWe'll say firefox not foundRun this command to install firefoxSo I'm pretty sure these tools come standard with your machineBut you can install them if you needSo Redelf as it sounds likeIs a tool that allows us to inspect the contentsOf elf format and minorsAnd Redelf generates a lot of outputSo it actually snipped off quite a bit of itBecause a lot of...So loading programs is actually remarkably complicatedAnd the earlier versions of this class at HarvardUse to spend several lectures talking aboutLinking and loadingAnd I don't want to do thatIt's complicatedIt's not really an operationIt can function completelyAnd it's justI don't find it to be super losingSo I'm going to gloss over a lot of detailsBut I do want to show you what's in hereYou want to learn more about thisThere's lots and lots of informationBut the process of running a fileOn modern systemsIs fairly involvedSo let's look at...Let's try to glean some simple bits of information about thisSo if I run RedelfI'm looking at bin trueI want to find the simplest possible program on thisWhat does bin true do?No, it does not return oneThe exit code that indicates everything is okaySo bin true is not a very big fileBut bin true still has eight different program headersSo the elf file has all the structure built into itEssentially, you know, it's like it's any of the filesThere's an agreement between the operating systemAnd the people who produce elf filesCan you compile and build somethingAbout how this file is set upAnd the elf standard is actually implementedI think back in 1999And now most versions of UNIX use thisSo if you...It provides some degree of portability between systemsRightSo if you take a binary that was compiled on one systemAnd try to run it somewhere elseIt may not because there's still some systemSpecific information that ends up being hard codedAnd here like the location of librariesAnd stuff like thatSo it's not always the case that you can compileSomething on, you know, BSEAnd run the identical binaryRightBut usually versions of UNIX are binarySo you can move binary backSo what's in here, rightSo someone told me something about this elf fileThat they can clean from thisAnd I'm giving you guys some hintsI'm using a highlightCharl, all the way in the backTell me something about this fileThis elf fileWhat does it say?And there you goEntry point, rightSo the entry point, what does the entry point sound like?What does that sound like?That is the first instructionThat this program will start to executeWhen it is finished loadingSo once the kernel is set upThe address page, according to the rest of thisThe first thread at address80 million 48 8 9 0That's a virtual addressTalk about virtual address nameAnd a few weeksBut that is where the first thread will startActually, it's not 80It's 80, well whateverIt's not like thatOkayNow let's look at the rest of itSo someone else told me something about thisHopped out by thatLet's work this outAnd tell me about this fileFrom the information that's provided byLoad elfRead elf, sorryCan you tell me something else?No, okayWe'll be backIt's an executableOkay, he took the easy routeWhat other file types do you think elf might support?Executable is notThat's not the permissionsThat's something about what the file is intended to doSo elfThe executable andIt's up on the slideRead the name of theRead what elf stands forIt'll give you a big hintExecutive only rulesSo what other file type might it support?A linkLike a loadable librarySo libraries were also created using itIn the elf formatThey're different kind of fileThey're not designed to be executedThey're designed to be loadedBy other executable filesSo this is the differenceAlright, let me goKeep going back hereSo tell me something else about this fileRead the parts in greenWhat program interpreter would it like?So this is kind of interestingI just puzzled by this myselfWhen I read this last nightSo it turns outSo if people have used LinuxYou'll notice that the file nameOf this file looks like a librarySo this is a standard format for librariesIt saysSo usually means a shared object fileOr a shared libraryNow it turns outThis is actually an executableRight, on your systemAnd if you'll read thisRight, it is one of the thingsI love about LinuxYou've tried to run somethingAnd there's this, you know10 line explanation of what it doesAnd why you probablyDidn't want to run itRight, you knowConclusions, chances areYou did not intend to run this programAnd that's usefulBecause I did intend to run itBut I was just trying to figure outWhat happenedSo it turns outThat the L file formatAllows each executableTo tell the kernelAfter you load my address spaceThis is a linkerThat I want you to startThat's going to help mapMy loadable librariesInto my address spaceSo there's actually two phasesAgain, I said this was possibleAnd I don't want to getBogged down in itOr confuse peopleBut afterThere are two phasesTo load in real lifeThe kernel loads upBeen trueAnd the next thingIs the kernel will startLive loadlinux.sodep2And that is the programThat will helpBeen trueMap the librariesThat it's usingSo there's two partsNow why is thatWhy would that be the caseWhat's the advantageOf using shared librariesTalk about thisA little bit moreThatRight, and what elseWhat can I doThe executable file is smallerIt's smaller whyBecause it's not being copiedIt doesn't containAnd what else does that meanIt has lessBut what elseSo remember beforeWe talkedThis is interestingSo before with file handlesWe talked aboutSeparating informationIn the different partsAllows me to do whatWhat's thatWell, okayBut the fundamental ideaHere is thatIt allows me to share things differentlyWhich means I canChange different thingsSo by not mappingLoadable librariesInto the outer spaceInside the executable fileWhat does that allow me to doIt allows me to change themIndependently of the fileSo if I makeFor exampleNow thisI haven't shown itThat this executableUses the C libraryRightMany C executablesUse the C libraryIf there's a bugIn the C libraryI only have to fixThe C library onceAnd every processThat loads it dynamicallyWill benefit from thoseChangesRightSo by not copyingCode aroundIt also allows meTo change that code onceThe one placeAnd then everyEvery programThat uses that codeRightAgainI get tiredJust talking about itIt's reallyAgainIt's just aSome sort of signalAbout how complicatedThis isI don't really wantTo go into itBut exactlyIt's the functionThat changesIn outer spaceAnd it usesIn Assignment 2You will learnA little bit moreAbout thatYou knowFear 9On your systemThere are noBasicallyThe L4 methodWe useIs really simpleWe don't implementAny sort ofShare librariesOr runtime linkingSo you don'tHave to worryAbout thatBut you willProcess an L fileAnd use theInformation to loadEven into an addressRightQuestionsAbout any of thisYeahSoIf youOkaySoIn the rest of theOutputRightSo I would encourage youTo look at theOutput at this fileRightAnd in fullAnd in the restOf the outputThere areThere areBasically commandsIn the L fileThat tellThe systemI want to useThis libraryRightThe next thingThat happensIs the systemHas to findThat libraryRightSo if youWant to changeThat libraryWhat do you doNoNoNoI changeThe file on diskThen it loadsRightSo if IMake a changeTo the C libraryRightWhich happensLike sometimesWhen you updateYour systemThere's a new versionOf the C libraryOr some otherShare libraryThat comes inThat fixes bugsOr improves performanceOr whateverRightBecause for exampleI may knowHow to call certain functionsBut I don't knowWhere they areIn the fileRightI know I want to useA certain C library functionBut depending onHow the library is set upThat function moves aroundRightSo part of gettingThis rightIs figuring outPixingSo a lot of thisGet stitched togetherAt runtimeThe program knowsThat it wants toYou know callI don't knowA string comparisonFunction in the C libraryBut it doesn't knowWhere that function isRightSo that's the mysteryThat gets sorted outAt runtimeRightIs that the linkerHelps it figure outWhen you want to callThat functionWhere do you jump toLike what memory addressDo you go toAnd start nextRightAny other questionsAboutDaleIs it possibleIf you're making changesTo these thingsThat someone is writingAn old versionAt the same timeSureIt's going to beAlso runningTo be honest with youI don't knowExactly about that workSo I think thatBecause I thinkThat's going to be fineBecause onceThe thing isThat the linkerSets up all this informationRightBased on the state of the worldOf a linker runSo if you change thingsAnd the function at your pointTo move aroundIn the capitalAnd then onlyI think thatAlsoSo based on this studyYou can move by nowLike you have to reboot windowsAnd you sayI think thatSo that may beThat may be one reasonBut I don't knowThat's a great questionActuallySo yeahIt's interestingThere was a lot ofThere's a period of timeIn the operating system communityWhere reboots wereA source of fair amount of conservationAnd there's actuallyA lot of interestingResearch that was doneBecause a lot of timesThe reasons why systems rebootIs just to get backTo a known good stateRightThey don't knowExactly what's happenedBut they knowWhat's predictableWhich is to boot intoAnd I don't knowI'm sure there's been studies on thisBut I think if you lookYou find that for a long timeA lot of the rebootsThat windows requestedWere probably not necessaryRightIf you knew exactlyHow to detangle thingsAnd which things to restartAnd everythingYou could avoid doing a rebootBut rather than figure that outBecause it's hardThey were just like thatPunt rebootNoBut there was a lot of workInto thisBecause people understood thatPeople get tired of rebootingTheir systems all the timeRightAnd people had aSmall asideI was working at Microsoft ResearchOne summerAnd it was right after Vista came outAnd we came in forTo start our internshipAnd they had theseLike nice new machinesWaiting for usAnd they all had Vista onRightAnd people were coming inAnd they're starting to getTheir environment set upAnd people just ranInto these issues with VistaRightSo this one guy, for exampleHad some sort of experimentRunning overnightRightAnd what happened overnightRightAnd I didn't want it to rebootRightSo it like neededAnd it's some criticalSecurity update to installSo it basically rebootedBecame the next dayIt's likeWhat happened to my experimentAnd it was justIt was goneSo I think withinI'm not making this upI think within aMaybe three weeksEverybody in the oppositeCalled up ITAnd asked to haveXB installed our machineSo basically everybody justRan away from Vista and XBAnd for what we wereDoing, it was more suitableBut anywayRightSo reboots are frequentlyNot really requiredBut sometimesIt's just the safest thingRightOn the other handThere's also these enterpriseSystems that just could notReally can haveBe rebootedRightThere are systems out thereAnd there are system administratorsOut there who I guarantee youThe thing they fear the mostIs that they will haveTo reboot their systemBecause they have no ideaHow to get it backInto the state that it's in nowRightI'm seriousIt's been up for a couple of monthsHe made a lot of configuration changesHe restarted thingsWe've got stuff to stabilizeAnd then someone's likeOh yeah, this is how for a patchWe need to rebootThey're like noNo, we don'tWe will just beAnd that may be one of the reasonsWhy systems continue to runUnpatched codeThat has problems with itRightSo one of the reasonsThat people are able to pull off exploitsIs because system administratorsDon't want to restartRightBecause they're never sureWill it ever run?Will it ever run again?Like will it ever run againThe way I got itRight nowSoOkayLet's forge aheadSoExecThe semantics are the exactAre that the parent processIs allowed to pass argumentsTo the childRightAnd this is importantBecause normallyThere are argumentsThat you want to pass to the childRightMost programs accept some argumentsAnd if you couldn't pass argumentsTo the childThen you wouldn't be ableRun important argumentsAnd it would be kind of dullRightI guess you could haveEvery program prompt youFor the argumentsThat you want to useBut then that makes itPossible to run pipelineSo why am I justifiedThis is just goodOkaySo anywayAnd the processPassing argumentsEssentially meansThat the calling processThe process that callsExactlyPasses some argumentsInto the kernelRightThose argumentsHave to be retrievedCarefully about the kernelRightBecause the kernelDoes not trust usersRightAnd you guys will findIt's not the time toMove argumentsAnd out of the kernelBecause the kernelHas to be very carefulWhen it's accessingUser addressesBecause the userCould be trying to do somethingMeOr could justDone something stupidRightSo the kernelRetreats the argumentsIt sets upA new address spaceAnd then it laysOut those argumentsIn the address spaceWhere the processCan findAnd when it starts to runRightAnd you guys knowThisBecause if you programRightAnd main takes an rpcAnd rpRightWhere does that come fromRp comes fromRightIt comes fromThat's the list of argumentsAnd that's how that getsRightOkayAnd thenThis is itI thought this was kind ofInterestingInteresting dualityBetween fork and excelRightSo what was interestingAbout forkIn terms of returnIt turnsIt turnsIt turnsYou guys are getting thereIt turns twiceRightExactExact on the other handAsThe interesting propertyWhere exact never returnsRightSo there's no returnFor exactRightExactI mean you can think ofExact as quoteAnd quoteReturningRightWhen you call exactAnd it worksThat's the end of youRightLike you will neverSeeYou will never knowIf it's exactOther thanThat you don't existIt worksOkaySo let's goLet's goThe guyThe guyOkaySo I got a threadSorryI got a processThat is called exactRightAnd my shellWants to run been trueOkaySoWhat's the first thingI need to doRightSo the threadIs now running insideThe kernelRightIt's my user kernel boundaryHereSo the processIs made a system calledRun inside the kernelWhat's the first thingI need to doHereNo, do I need to run fork?No, fork and exec are totally...Okay, I need to read the file.Let's see, what did I do first?I need to get the arguments, right?So the arguments are...When I call exec, the arguments are located in memory.There's actually...I can actually pass a certain number of argumentsdirectly to the system call,but there's a limited number of registers on my CPUand so I usually have to leave something in the number.So I've got arguments for the new...I've got arguments for beenTrue in the memory of back.I've got to copy these into the kernel.Now I've got my argument.I guess I should have copied them.I didn't move them.They get copied.What's next?You've got an L in my hand.So now I've got to open up the L file.So I've got my beenTrue fileand as we point out before,the new file tells mehow to set up the outer space for this new file.So there's new process.What are the contents of memorythat should be loaded when this process starts?What do I do next?What's that?I think I did this differently.So what I did next isI've replaced the outer space.And now...What do I do?Somebody had the right answer.I need to push the R.Now the arguments go back.Let's go through this a few more times.I'm also realizing thatI think there's something that's out of order here.So this is a good question.So what I've shown you here isI set up the outer spaceand then I destroy the outer spaceof the process that called itand thenI copy the arguments back in.So what's the problem with my information?No, my arguments are in the kernel now.So that's okay.I copied them into kernel.Yeah.So this is performance issues.I'm more worried about failure.Soif there's a problemcopying the argumentswhat happens here?We'll fail,but can I go back?No.Right.So this is one implementation...So this is one implementationchallenge with exec.Exec either has to...Exec can't get stuck in some indeterminate state.So exec can't...There have to be the same number of processesafter I call exec as before.I can't failand then accidentally be likewhoops,sorryI'm not going to return to the caller.I'm just going to pretend like that didn't happen.No one saw it.So when exec failsit has to return back to the caller.So I have to make all the changesthat I have to set up.The other thing for my new processanything that can fail has to be donebefore I make structure changesto the caller's atmosphere.But of course,againthese processes are just abstractions.So let me go back to my example here.We'll talk about the file head of department.So right herethere's no need for meto replace this address space in this step.I can just keep two address spaces aroundto the very,very last minute.And I can essentially copy the argumentsinto this address space.I can do everything I need to doand then actuallyI can just start the new thread runningover here.I can create a new process container.And then once everything is set upI can kill the new process.So again,when you guys get them with thisI think they'll start to get itwhich is thatthese are just abstractions,right?So there's no real box herethat I can only have one address space.Yeah.If anything succeedsDo you want to return to the bash,right?No.No,no,no.Bash is no more.If execs succeedswhen execs succeedsthe calling process is gone.Go on.Yeah,in case of execbut usually when we usebash and run throughthen we come back to the bash.We'll get to that.Right?So what bash actually doeswe're going to get to our show.Let me keep going.So execone thing about exec is thatby convention exec does not modifythe file tableof the calling process.So if you saw hereI didn't do anything to the file tableI just left it alone.Walking.Because you want to shareif that is between the bear and the butcher.TAs are just so old.Right.So I did all this workin fork to copy the file tableand make sure the parentand the child had the samefile handles,right?If the next thing I do after forkis execand I blow wellit meansI can never reallyimmediate the wayto watch it.Right?So execto use the file tableexactly in this.Right?So by defaultthe process startsexecuting with thesame open files.Same file handles.So this isthe beginningof our simple shell.Right?You can write a shellin pseudo codeif you ignoresome little gummy bitslike how to parsethe argumentsin about 7 or 8 lines.Right?So this isthe beginning.Right?So what does this code do?Oh,I should haveprinted a promptWhat does this code do?Right?So Iread a line of inputfrom thefrom the shelland againif I wouldsimple made a real shellI would havea pretty promptto tell youthat I'm readyfor integer.Right?But Iread a line of inputand again I justmade up this functionit doesn't existand then I fork.Right?Because I'mgoing toI want to stay aroundbecause Iwhat happens if Ijust call execI could do that.Right?I could just callexecWhat would happen then?The shell is gone.Right?There's no shell no more.Right?So Icould just call execand then when thatprocess exitedthat would be the end.Right?There'd be noshell for meterperfume.Right?So I wouldn't be able torun it.If Iwant to write a shellthat only takesonly executesone line of inputthen that works fine.Right?But that's nota very useful shell.Right?So I call fork.So ifthe shell is zeroso what does this mean?And the childI call execand I replace myselfwith whatevernew processthe user wanted to start.Right?So this is reallyit's almost just simple.Right?Butwhat's missing here?Right?What wouldactually happenif I ran this code?What's that?Well you knowwhat's going to happenis it's going to come backto this line hereinput.Right?And nowwhat's going to happenis it's actuallygoing to be competingfor the consolewith whatever started up.Right?You can write the shellit's really annoying.Right?Because it's likebecause basicallythe characters areboth processesthey're sharingfile handles.Remember?So both processesare tryingto grab charactersfrom the consoleand it's kindof like whoever wins.Right?And soit's very difficultto speak to me.That's becausethe shell is sitting theretrying to get some.Right?Okay.Sowhat I needto dowhen I need to dois implementwell this couple thingssowe talked about this alreadywhat am I missingherein my process problem?there's two pieces leftand thesethese areI think in many waysmuch simpler than they are.Okay well noyou're getting ahead of me.Sohow does the processindicate that it'sfinished execute?Right?Wellit turns outthat there's actuallya system call for this.Right?Soyou guys who haveI'm going to come backto the end of theanyone who'swhose written C coderight?Doyou have to callexit at the end你的名字不不不原因是C library 叫 exit 40所以when main completescontrol 其實returns into the C libraryand the C library will call exit problembut every processin order to exitcalls as exitthis is the callexistence of call takes an exit codeand that exit codeis delivered to parentit's made available to parentbut nowso exit is very simpleexit just destroys the process of the callrightI don't even know if exit can actually failif you call exit you're donethere's no trace of you left on thisexcept for this exitrightbut as Michael pointed outI need a wayto figure outhow to communicate that exit codeto the parentso the last call on our listfor today is waitso when a process calls exitthe kernel maintains an exit codefor that processand it maintains that exit codeuntil the parent calls waitwait is another system calland the standards of waitare I give wait a process IDand if that process IDis one of my childrenthen wait will return the exit codeand again wait is the one system callthat I can't figure out exactlyhow to fit intoI was thinking it's kind of likebecause the thing is thata process can call waiteither before or afterthe trial is exitedif it calls wait beforeit's kind of likeI guess it's your parentbut imagine it's like a relativewaiting at your bedsideis you're dyingjust die alreadyso I can reach the wealthof this exit codethat you're about to provideI took care of you for monthsand all I got was this lousy itso if it calls afterand it's almost like a salebeyond the grave of communicationyou know like people gatherand a spirit appearsand the spirit saysforokay soso wait and exit are frequentlyconsidered togetherand the reason is thatboth wait and exit are requiredto completely removeall traces of a processfrom our systemso untila process calls exitand its parent calls waitsome trace of that processis left on the systemit turns outthat there are two piecesone is the return codethe other is the process IDso the process IDwill not be reusedwhy notwhy notwhy wouldn't I reuse process IDrightif I didn't reuse the process IDthen when the parent calls waitI'm likeyou're talking about process 5you're talking about process 5you're talking about process 5you're talking about process 5you're talking about process 5we got a lot of exit codesfor process 5I don't know which oneso the process IDusually hangs aroundbecause it'sneeded to a new type ofplatformso processes thatof exit have notyet had theirexit codewe call thisa reapedrightlike the grim reaperand nowprocesses thatof exit have anadversed code reapedare called zombiesrightand all thatmeans is thatthere's some teenylittle bit of informationleft about this processit's deadit doesn't have anadversed baseit doesn't have any threadsetc.some traceit's stillsogetting weightedexit lifeis going tobedebly a little biton assignment toobecause it createsinterestingsynchronizationrighta processthe semanticsof weightare that a processis supposed to beguaranteed to beable to collectthe exit codeof its childrenrightwhen a child exitswhoever its parentis at that momentis supposed to beable to collectthe exit codeandthe parentis calling weightand the childis calling exitrightaround the same timerightand in thosekind of race conditionsyou have to make surethatyou knoweither one of two thingshappenseither weight succeedsand returns to the exit codeor weight failsbut the exit codeis still availablerightsoit turns outthat there are alsook so let's talka little bit aboutwait an exitsoso what do I doif a processis parentsopairis supposed to be the onepairis supposed to be the onethat's responsiblefor collecting the exit codewhat do I doso I need toI need to find a newthe terminology gets weirdso we refer tothis processas an orphanand we needto find a new parentand normallywhat we dothe standard semanticsare the orphan processis assignedto initright and probably在系統上都會經常發生一直在發生一直在發生所以我父母死了我仍然在發生所以其他問題是我們可以防止狀況嗎所以當孩子死了直至父母的肺炎或是每個系統的父母可以在發生這小段時間就已經發生所以我們可以防止如果我們在發生有時候我們可以找狀況在發生的狀況對嗎還有其他東西但是我可以保證我沒有很多的不太多這些狀況在發生給他們一點時間給他們一點時間給他們一點時間所以你意思是什麼殺了之後的不所以重點是肺炎永遠都要回復什麼我一開始叫他們找到的正確訊息那他們的狀況沒有合作繼續夠了只有或太多所以有兩個理解第一個就是孩子死了腿along肺炎肆腸我不知道為什麼會不會肩我再來看像只有7個8個是有時候會生所以,當我獲得這個信號,這個信號給父母,這個信號是可以給孩子的而很多父母會用這個信號來代替他們即使他們不想用這個信號,即使他們不想用這個信號他們會用這個信號來代替他們即使他們不想用這個信號,即使他們不想用這個信號所以,在某些系統上,在某些系統上,如果父母選擇去代替這個信號那麼,父母會把孩子給你所以,如果我把這個信號傳給父母,父母會去代替這個信號所以,如果父母不在乎這個信號,我就會把這個信號傳給他所以,我會用這個信號來代替這個信號所以,如果父母不在乎這個信號,我就會把這個信號傳給他其實,對不起,這是一句對不起,我忘記了這句所以,其他問題是,如果我不想等如果我想看看父母的招數,或者看如果父母死了我應該說這樣,如果我想看父母死了,我會有兩種選擇一種是,我可以補充所以,原本的計劃是,父母會等到父母死了如果父母還活著所以,如果父母死了,他會補充這個信號如果父母還活著,他會等到父母死了當時,父母就會開始在乎這個信號所以,有人問我之前的問題是否真正的,這就是父母的想法所以,父母會等到你等到你開始繼續在乎這個信號用來補充這個信號還有一種補充這個信號讓我簡單地說所以,補充這個信號會補充這個信號,如果父母死了如果父母死了,他就會補充這個信號這個信號會補充這個信號好,現在,我們其實有這個信號所以,這是我們的簡單信號所以,這是什麼來源讓我們避免這個問題讓我們避免這個問題讓我們避免這個問題讓我們避免這個問題讓我們避免這個問題所以,如果我,父母我會等到我的兒子那兒子所以,這是另一個問題那兒子在哪裡?我已經說過,我以為我會用這個信號那兒子在哪裡?父母在兒子因為,這個信號的全程是父母的信號對然後,父母也會用這個信號所以,我們要快速地讓我們把Aerono和C-Library的分別所以,你們一些人有用過一些信號的信號或,我應該說你們覺得你們用過一些信號的信號對吧? turns out that the forkthat you call when you program in Cis not a direct system callWhat it does, it's a function provided by the C-Librarythat changes the semantics of fork's likenessRight?So, you call the C-Library functionI think sometimes it's even implementedit's just a macroRight?And what it doesis it takes the arguments you passit might rearrange them a little bitand then it passes them into the kerneland then when the kernel returnsone of the significant things it doesis it sets AeronoRight?So, people who use Care familiar with AeronoAerono is a global variablethat set that indicatesafter I make a certain systemor library callsif there was a problemRight?The kernel does not set AeronoRight?The kernel simply returns argumentsor returns an exit codefrom a system callRight?The C-Library is responsiblefor calling AeronoRight?So, I just want to pointand make sure you guys understandwhen you start to do a signature tuneyou start to read aboutwhat your acts to implementthe semantics of sys-4sys-6sys-waythe system callversions of theseare differentthan you might be used toif you're really familiarwith the formatting of CRight?So, just keep that in mindRight?And you get if you want toyou've got all the codefor your systemso if you want to seehow the C-Librarythat I gave youthat we gave youmodifies the argumentsgo look at itit's right thereevery time when youdo a make in your sourcedirectoryand you compile allthe user toolsone of the thingswe're going to takeyou knowwe've basically been up herewe've been lookingat the kernelfrom the perspectiveof applicationswe've been lookingat the kernel interfacethe system callOn Mondaywe're going to startwhat might bea little bit more funwhich is getting downand dirty intothe world of hardwareRight?So, we're going to talk aboutwhat are the problemswith hardwarewhat are the key abstractionswhat are the thingsthat the kernelhas to be able to dothe multiplex resourcesand create thesecomputed plansto try to dobasically a weekand you knowinterruptshow the kernel getscontrolspecial featuresof kernel codeand a lot ofdo certain thingscomputingand a little bitabout the frontthen we're going todo a weekon synchronizationwhich you willappreciatebecause by that pointwe've beenon assignment onewhich has a lotof synchronizationand then we willdo a weekon scheduleand that'sas far as I can