Homework 2

22C:116, Spring 1995

Due Friday Feb. 3, 1995, in class

Douglas W. Jones

To prepare for this homework assignment, read the the Unix man pages on the read(), write(), close(), pipe(), fork(), exit() and wait() system calls (for any UNIX system, you should find these in section 2 of the manual). Note that some of these are very complex, but that, for the purpose of this assignment, the only relevant details involve the interaction between these system calls, and not their relation to other calls. These primitives provide Unix with a fairly general set of tools for writing parallel programs where the processes making up the parallel programs communicate via FIFO channels.

Note that the notation cobegin a; b; c coend is frequently used to indicate the execution of statements a, b and c in parallel, while begin a; b; c end indicates that a, b and c are executed in sequence.

  1. Write Unix code (using the programming language of your choice, and note that you need not run it!) that is equivalent to the following pseudocode, where a, b and c are statements.

    cobegin a; b; c; coend

  2. Write Unix code equivalent to the following pseudocode, where a, b, c, d, e, f, g, h, i and j are statements.

    begin

    end

    Note that this second problem is a bit tricky because the cobegin coend notation doesn't imply parent-child relationships, while the Unix fork primitive establishes a clear set of parent child relationships. Furthermore, this problem has been constructed in such a way that you are forced to create a parent with more than one child and then wait for one specific child to terminate.

  3. What, if any, are the significant differences in the pipe commands of Ultrix, HP/UX and Sunos, as documented in their respective man pages.

  4. The documentation of the possibility of deadlock in the SUNOS man page for pipes is in error. What is the error?