DOC PREVIEW
CMU CS 15410 - Lecture

This preview shows page 1-2-16-17-18-34-35 out of 35 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

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, S’04- 1 -The ProcessJan. 21, 2004Dave EckhardtDave EckhardtBruce MaggsBruce MaggsL05_Process15-410“System call abuse for fun & profit”15-410, S’04- 1 -SynchronizationProject 0 due at midnightProject 0 due at midnightPlease go through the hand-in page nowAnybody reading comp.risks?Anybody reading comp.risks?TodayToday–Chapter 4, but not exactly!15-410, S’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, S’04- 1 -The ComputerStackProgramRegistersKeyboardScreenTimer15-410, S’04- 1 -The ProcessStackCodeDataHeapRegistersstdinstdouttimer15-410, S’04- 1 -Process life cycleBirthBirth–(or, well, fission)SchoolSchoolWorkWorkDeathDeath(Nomenclature courtesy of The Godfathers)(Nomenclature courtesy of The Godfathers)15-410, S’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, stack–CPU register contents (N of them)–"I/O ports"●File descriptors, e.g., stdin/stdout/stderr–Hidden “stuff”●timer state, current directory, umask15-410, S’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...15-410, S’04- 1 -Birth – fork() - 1MemoryMemory–Copy all of it–Maybe using VM tricks so it' s cheaperRegistersRegisters–Copy all of them●All but one: parent learns child's process ID, child gets 015-410, S’04- 1 -Birth – fork() - 2File descriptorsFile descriptors–Copy all of them–Can't copy the files!–Copy references to open-file stateHidden stuffHidden stuff–Do whatever is "obvious"ResultResult–Original, “parent”, process–Fully-specified “child” process, with 0 fork() parameters15-410, S’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 text–Implant new registers!●Old ones don't point well into the new memory–Keep (most) file descriptors●Good for cooperation/delegation–Hidden state?●Do what's “obvious”15-410, S’04- 1 -Original ProcessStack/bin/shDataHeapRegistersstdinstdouttimer t=415-410, S’04- 1 -Toss Heap, DataStack/bin/shRegistersstdinstdouttimer t=415-410, S’04- 1 -Load New Code, Data From FileStack/u/b/gccDataRegistersstdinstdouttimer t=415-410, S’04- 1 -Reset Stack, HeapStack/u/b/gccDataRegistersstdinstdouttimer t=4[Heap]15-410, S’04- 1 -Fix “Stuff”Stack/u/b/gccDataRegistersstdinstdouttimer off[Heap]15-410, S’04- 1 -Initialize RegistersStack/u/b/gccDataRegistersstdinstdouttimer off[Heap]15-410, S’04- 1 -Begin ExecutionStack/u/b/gccDataRegistersstdinstdouttimer offHeap15-410, S’04- 1 -What's This Procedure Called?int execve( char *path, char *argv[ ], char *envp[ ])15-410, S’04- 1 -Birth - other waysThere is another wayThere is another way–Well, twospawn()spawn()–Carefully specify all features of new process–Don't need to copy stuff you will immediately tossPlan 9 rfork() / Linux clone()Plan 9 rfork() / Linux clone()–Build new process from old one–Specify which things get shared vs. copied15-410, S’04- 1 -SchoolOld process calledOld process calledexecve(char *path,char *argv[ ],char *envp[ ]);Result isResult ischar **environ;main(int argc, char *argv[ ]){ ...}15-410, S’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 memory–Toss old stack memory–Load executable fileAlso...Also...15-410, S’04- 1 -The Stack!Kernel builds stack for new processKernel builds stack for new process–Transfers argv[] and envp[] to top of new process stack–Hand-crafts stack frame for __main()–Sets registers●Stack pointer (to top frame)●Program counter (to start of __main())15-410, S’04- 1 -WorkProcess statesProcess states–Running●User mode●Kernel mode–Runnable●User mode●Kernel mode–Sleeping●In condition_wait(), more or less15-410, S’04- 1 -WorkOther process statesOther process states–Forking–Zombie““Exercise for the reader”Exercise for the reader”–Draw the state transition diagram15-410, S’04- 1 -DeathVoluntaryVoluntary void exit(int reason);Software exceptionSoftware exception–SIGXCPU – used "too much" CPU timeHardware exceptionHardware exception–SIGSEGV - no memory there for you!15-410, S’04- 1 -Deathkill(pid, sig);kill(pid, sig);^C  kill(getpid(), SIGINT);Start loggingStart loggingkill(daemon_pid, SIGUSR1);% kill -USR1 33Lost in SpaceLost in Spacekill(Will_Robinson, SIGDANGER);–I apologize to IBM for lampooning their serious signal●No, I apologize for that apology...15-410, S’04- 1 -Process cleanupResource releaseResource release–Open files: close()●TCP: 2 minutes (or more)●Solaris disk offline - forever (“None shall pass!”)–Memory: releaseAccountingAccounting–Record resource usage in a magic fileGone?Gone?15-410, S’04- 1 -“All You Zombies...”Zombie processZombie process–Process state reduced to exit code–Wait around until parent calls wait()●Copy exit code to parent memory●Delete PCB15-410, S’04- 1 -Kernel process stateThe dreaded "PCB"The dreaded "PCB"–(polychlorinated biphenol?)Process Control BlockProcess Control Block–“Everything without a memory address”●Kernel management information●Scheduler state●The “stuff”15-410, S’04- 1 -Sample PCB contentsPointer to CPU register save areaPointer to CPU register save areaProcess number, parent process numberProcess number, parent process numberCountdown timer valueCountdown timer valueMemory segment infoMemory segment info–User memory segment list–Kernel stack referenceScheduler infoScheduler info–linked list slot, priority, “sleep channel”15-410, S’04- 1 -Conceptual Memory LayoutStackProgramk-stackk-stackk-stackk-stackKernel DataKernel


View Full Document

CMU CS 15410 - Lecture

Download Lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?