Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 3515-410, F’04- 1 -The ProcessSep. 13, 2004Dave EckhardtDave EckhardtBruce MaggsBruce MaggsL06a_Process15-410“Now I know why they call it a 'cursor'”15-410, F’04- 1 -SynchronizationProject 1Project 1Hope you've run simics by now!“End of today”paint character on screenposition cursorAnybody reading comp.risks?Anybody reading comp.risks?This lectureThis lectureChapter 4, but not exactly!15-410, F’04- 1 -OutlineProcess as pseudo-machineProcess as pseudo-machine(that's all there is)Process life cycleProcess life cycleProcess kernel statesProcess kernel statesProcess kernel stateProcess kernel state15-410, F’04- 1 -The ComputerStackProgramRegistersKeyboardScreenTimer15-410, F’04- 1 -The ProcessStackCodeDataHeapRegistersstdinstdouttimer15-410, F’04- 1 -Process life cycleBirthBirth(or, well, fission)SchoolSchoolWorkWorkDeathDeath(Nomenclature courtesy of The Godfathers)(Nomenclature courtesy of The Godfathers)15-410, F’04- 1 -BirthWhere do new processes come from?Where do new processes come from?(Not: under a cabbage leaf, by stork, ...)What do we need?What do we need?Memory contents●Text, data, stackCPU register contents (N of them)"I/O ports"●File descriptors, e.g., stdin/stdout/stderrHidden “stuff”●timer state, current directory, umask15-410, F’04- 1 -BirthIntimidating?Intimidating?How to specify all of that stuff?How to specify all of that stuff?What is your {name,quest,favorite_color}?Gee, we already have Gee, we already have oneone process we like... process we like...Maybe we could use its settings to make a new one...Birth via “cloning”15-410, F’04- 1 -Birth – fork() - 1““fork” - Original Unix process creation system callfork” - Original Unix process creation system callMemoryMemoryCopy all of itMaybe using VM tricks so it' s cheaperRegistersRegistersCopy all of them●All but one: parent learns child's process ID, child gets 015-410, F’04- 1 -Birth – fork() - 2File descriptorsFile descriptorsCopy all of themCan't copy the files!Copy references to open-file stateHidden stuffHidden stuffDo whatever is "obvious"ResultResultOriginal, “parent”, processFully-specified “child” process, with 0 fork() parameters15-410, F’04- 1 -Now what?Two copies of the same process is Two copies of the same process is boringboringTransplant surgery!Transplant surgery!Implant new memory!●New program textImplant new registers!●Old ones don't point well into the new memoryKeep (most) file descriptors●Good for cooperation/delegationHidden state?●Do what's “obvious”15-410, F’04- 1 -Original ProcessStack/bin/shDataHeapRegistersstdinstdouttimer t=415-410, F’04- 1 -Toss Heap, DataStack/bin/shRegistersstdinstdouttimer t=415-410, F’04- 1 -Load New Code, Data From FileStack/u/b/gccDataRegistersstdinstdouttimer t=415-410, F’04- 1 -Reset Stack, HeapStack/u/b/gccDataRegistersstdinstdouttimer t=4[Heap]15-410, F’04- 1 -Fix “Stuff”Stack/u/b/gccDataRegistersstdinstdouttimer off[Heap]15-410, F’04- 1 -Initialize RegistersStack/u/b/gccDataRegistersstdinstdouttimer off[Heap]15-410, F’04- 1 -Begin ExecutionStack/u/b/gccDataRegistersstdinstdouttimer offHeap15-410, F’04- 1 -What's The Implant Procedure Called?int execve( char *path, char *argv[ ], char *envp[ ])15-410, F’04- 1 -Birth - other waysThere is another wayThere is another wayWell, twospawn()spawn()Carefully specify all features of new processComplicatedWin: don't need to copy stuff you will immediately tossPlan 9 rfork() / Linux clone()Plan 9 rfork() / Linux clone()Build new process from old oneSpecify which things get shared vs. copied“Copy memory, share files, copy environment, share ...”15-410, F’04- 1 -SchoolOld process calledOld process calledexecve(char *path,char *argv[ ],char *envp[ ]);Result isResult ischar **environ;main(int argc, char *argv[ ]){ ...}15-410, F’04- 1 -SchoolHow does the magic work?How does the magic work?15-410 motto: No magicKernel process setup: we saw...Kernel process setup: we saw...Toss old data memoryToss old stack memoryLoad executable fileAlso...Also...15-410, F’04- 1 -The Stack!Kernel builds stack for new processKernel builds stack for new processTransfers argv[] and envp[] to top of new process stackHand-crafts stack frame for __main()Sets registers●Stack pointer (to top frame)●Program counter (to start of __main())15-410, F’04- 1 -WorkProcess statesProcess statesRunning●User mode●Kernel modeRunnable●User mode●Kernel modeSleeping●“Blocked” awaiting some event●Not run by scheduler●Q: Is this user mode or kernel mode?15-410, F’04- 1 -WorkOther process statesOther process statesForkingProbably obsolete, once used for special treatmentZombieProcess has called exit(), parent hasn't noticed yet““Exercise for the reader”Exercise for the reader”Draw the state transition diagram15-410, F’04- 1 -DeathVoluntaryVoluntary void exit(int reason);Hardware exceptionHardware exceptionSIGSEGV - no memory there for you!Software exceptionSoftware exceptionSIGXCPU – used "too much" CPU time15-410, F’04- 1 -Deathkill(pid, sig);kill(pid, sig);keyboard ^C kill(getpid(), SIGINT);Start loggingkill(daemon_pid, SIGUSR1);% kill -USR1 33Lost in Spacekill(Will_Robinson, SIGDANGER);I apologize to IBM for lampooning their serious signal»No, I apologize for that apology...15-410, F’04- 1 -Process cleanupResource releaseResource releaseOpen files: close()●TCP: 2 minutes (or more)●Solaris disk offline - forever (“None shall pass!”)Memory: releaseAccountingAccountingRecord resource usage in a magic fileGone?Gone?15-410, F’04- 1 -“All You Zombies...”Zombie processZombie processProcess state reduced to exit codeWaits around until parent calls wait()●Copies exit code to parent memory●Deletes PCB15-410, F’04- 1 -Kernel process stateThe dreaded "PCB"The dreaded "PCB"(polychlorinated biphenol?)Process Control BlockProcess Control Block“Everything without a user-visible memory address”●Kernel management information●Scheduler
View Full Document