Assignment 12, due May 1

Part of the homework for 22C:112, Spring 2009
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated (usually a Friday). The only exceptions to this rule will be by advance arrangement unless there is what insurance companies call "an act of God" - something outside your control. Homework must be turned in on paper and in class! Late work may be turned in to the teaching assistant's mailbox, but see the late work policy. Never push late work under someone's door!

  1. Background: In unix, interprocess communications pipes are created using the pipe() system call. This creates a new pipe, a FIFO communications channel, and returns two file descriptors, one referring to the read end of the pipe, the other referring to the write end. (Use man 2 pipe for more detail.) Of course, the new pipe only known to one process, the one that created it, but after creating the pipe, that process may fork into multiple processes.

    See man 2 dup for mechanisms permitting open files to be moved to a different descriptor number, and note that if an open file is visible from two descriptor numbers, close() applied to one of its numbers does not close access to the file through the other number.

    A problem: Give a fragment of C code that launches two applications using execve(), call them "app1" and "app2", where standard output of "app1" is piped into standard input of "app2", while both applications remain able to read and write the other files that were open prior to your code fragment. Your fragment should wait for both child processes to terminate before it exits. (1.0 points)

  2. Background: Consider a client-server architecture. Assume that messages are sent and received from buffers in memory, and that the sender and receiver must specufy the buffer and its length. The following primitives are available:

    A problem: Write the code for a server that implements a single semaphore, with initial (abstract) value zero and client-to-server messages "P" and "V" corresponding to the wait and signal operations (names chosen in part because they are of length 1). You may assume pre-existing library implementations of such things as stacks and queues with the usual operations. (1.0 points)

  3. Background: In Unix, the resources available to a running program fall into three broad categories:

    In Amoeba and Demos, many resources that are statically accessible in systems modeled on Unix are, instead, passed in what can be thought of as analogous to the environment in Unix. Among the most important of these is the file system.

    a) What system data structure holds the envoronment of a Demos process? (0.5 points)

    b) What system data structure in Unix (or Linux) is analogous to the data structure you identified in part a. Note that this Unix data structure has a far narrower use than the use it has in Demos. (0.5 points)