DOC PREVIEW
Duke CPS 110 - Processes

This preview shows page 1-2-19-20 out of 20 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 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 20 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 20 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 20 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Processes, Unix, and IPCTodayMidterm ResultsProcess InternalsNachos Exec/Exit/Join ExampleProcess Management Example (Midterm Problem #4)Process Birth Example (Midterm Problem #4)Process Join Example (Midterm Problem #4)Process Death Example (Midterm Problem #4)Elements of the Unix Process and I/O ModelUnix File DescriptorsUnix File Descriptors IllustratedThe Concept of ForkUnix Fork/Exec/Exit/Wait ExampleExample: Process Creation in UnixWhat’s So Cool About ForkProducer/Consumer PipesUnix as an Extensible SystemThe ShellLimitations of the Unix Process ModelProcesses, Unix, and IPCProcesses, Unix, and IPCTodayTodayWelcome back•Midterm scores are on the Web; Lab #4 is where you left it.Today we continue with process management topics.•last time: address space creation/initialization•today: process interactions and synchronizationExec/Exit/Join synchronization (midterm problem #4)A peek at the Unix process model, its strengths and limitationsStart on mechanisms for Interprocess Communication (IPC)IPC mechanisms combine synchronization and data transferpipes, streams, messages, Remote Procedure Call (RPC)Midterm ResultsMidterm Results02550751001251501752001 16 31 46 61processsemaphoremcbealtweedleProcess InternalsProcess Internals+ +user IDprocess IDparent PIDsibling linkschildrenvirtual address space process descriptorresourcesthreadstackEach process has a thread bound to the VAS.The thread has a saved user context as well as a system context.The kernel can manipulate the user context to start the thread in user mode wherever it wants.Process state includes a file descriptor table, links to maintain the process tree, and a place to store the exit status.The address space is represented by page table, a set of translations to physical memory allocated from a kernel memory manager.The kernel must assign memory to back the VAS, and initialize it for the program to run.Nachos Exec/Exit/Join ExampleNachos Exec/Exit/Join ExampleExec parent Exec childJoinExitSpaceID pid = Exec(“myprogram”, 0);Create a new process running the program “myprogram”. Note: in Unix this is two separate system calls: fork to create the process and exec to execute the program.int status = Join(pid);Called by the parent to wait for a child to exit, and “reap” its exit status. Note: child may have exited before parent calls Join!Exit(status);Exit with status, destroying process. Note: this is not the only way for a proess to exit!.Process Management ExampleProcess Management Example(Midterm Problem #4)(Midterm Problem #4)ExecHandler (char* executable) Process* p = new Process();Process* parent = CurrentProcess();create and initialize VAS for p;p->Birth(parent);start thread in child context;allocate and return SpaceID;JoinHandler(int spaceid)Process* child = get from spaceID;int status = child->Join();return(status);ExitHandler(int status)Process* p = CurrentProcess();tear down p’s VAS, release memory;p->Death(status);delete p;destroy this thread;1. Parent waits in Join for child to exit (by calling Death).2. Exited child waits in Death for parent to join or exit.3. Exited parent waits in Death for children to exit.Needed:• 3 wait• 3 signal/broadcast each in (Join, Death, Death)Process Birth ExampleProcess Birth Example(Midterm Problem #4)(Midterm Problem #4)Mutex* pMx;Condition* pCv;voidProcess::Birth(Process *parent) {pMx->Acquire();this->parent = parent;parent->AddChild(this);status = 0;exited = 0;joinedOn = 0;pMx->Release();}pMx and pCv are global(could use private CVs, but it’s tricky)Process Join ExampleProcess Join Example(Midterm Problem #4)(Midterm Problem #4)intProcess::Join() {int status;pMx->Acquire();while (!exited)pCv->Wait(); /* wait for child to exit */status = this->status;joinedOn = 1;pCv->Broadcast(); /* tell child that parent is done */pMx->Release();return(status);}1. Parent waits in Join for child to call Death.2. Child waits in Death for parent to complete Join.Process Death ExampleProcess Death Example(Midterm Problem #4)(Midterm Problem #4)void Process::Death(int status) {pMx->Acquire();exited = 1; /* process has exited */this->status = status;pCv->Broadcast(); /* wake parent from join */while (!joinedOn && !parent->exited)pCv->Wait();parent->RemoveChild(this); /* parent may delete now */pCv->Broadcast();while (!children->Empty())pCv->Wait();pMx->Release();}1. Parent waits in Join for child to call Death.2. Child waits in Death for parent to call Death.3. Parent waits in Death for children to call Death.Elements of the Unix Process and I/O ModelElements of the Unix Process and I/O Model1. rich model for IPC and I/O: “everything is a file”file descriptors: most/all interactions with the outside world are through system calls to read/write from file descriptors, with a unified set of syscalls for operating on open descriptors of different types.2. simple and powerful primitives for creating and initializing child processesfork: easy to use, expensive to implement3. general support for combining small simple programs to perform complex tasksstandard I/O and pipelines: good programs don’t know/care where their input comes from or where their output goesUnix File DescriptorsUnix File DescriptorsUnix processes name I/O and IPC objects by integers known as file descriptors. •File descriptors 0, 1, and 2 are reserved by convention for standard input, standard output, and standard error.“Conforming” Unix programs read input from stdin, write output to stdout, and errors to stderr by default.•Other descriptors are assigned by syscalls to open/create files, create pipes, or bind to devices or network sockets.pipe, socket, open, creat•A common set of syscalls operate on open file descriptors independent of their underlying types.read, write, dup, closeUnix File Descriptors IllustratedUnix File Descriptors Illustrateduser spaceFile descriptors are a special case of kernel object handles.pipefilesocketprocess filedescriptortablekernelsystem open file tablettyDisclaimer: this drawing is oversimplified.The binding of file descriptors to objects is specific to each process, like the virtual translations in the virtual address space.The Concept of ForkThe Concept of ForkThe Unix system call for process creation is called fork().The fork system call creates a child process that is a clone of the parent.•Child has a (virtual) copy of the parent’s virtual memory.•Child is running the same program as the parent.•Child inherits open file descriptors


View Full Document

Duke CPS 110 - Processes

Download Processes
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 Processes 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 Processes 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?