Homework 10

22C:116, Fall 2001

Due Monday Nov 19, 2001, in class

Douglas W. Jones

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list!

  1. Programming Assignment: Write working code for an interprocess communication package that maintains, for each process, a set of mailboxes for incoming messages. Messages will be addressed to a particular mailbox of a particular process. Ideally, you will be able to implement this semantics as a layer on top of the software you implemented for homework 8, based on what you learned doing homework 9. Your code should implement the following primitives:

    send( dst, buf, nbytes )
    sends the contents memory at address buf, of length nbytes to the destination dst. The buf and nbytes parameter types can easily follow the model set by the read() system call. The parameter dst should be a tuple . Note that if you represent such a tuple with a struct called address, the following C, C++ syntax is a convenient way to send messages to a particular box of a particular process:
          {
              struct address x = {process, box};
              send( &address, buf, nbytes );
          }
    

    receive( box, buf, nbytes )
    awaits and receives a message addressed to the indicated box of the current process.

    Note that the specific semantics of send are not fully specified. It may be synchronous, semi-synchronous or nonblocking. This gives you considerable implementation freedom. Please pursue a low-effort implementation path!

    Test your work with a suite of 4 UNIX processes communicating as follows:

    1. Parent of all processes, reads from standard input and writes line by line to box 1 of process 2, awaiting a reply in box 1 for each message sent. Messages to box 1 process 2 include both the line of text and two message addresses, one is the message address to which the line of text should be forwarded, and the other is a return address. Awaits an empty reply message prior to processing the next line of text. All messages should be forwarded to either process 3 or process 4, alternately.

    2. Intermediate process, awaits messages in box 1, where each message is formatted as above. Replies immediately and then forwards the line of text as indicated, along with a return address, awaiting a reply before processing the next line.

    3. Print process, prints the message received and then replies.
    4. Print process, prints the message received and then replies.
      These two print processes are identical except that each prints a different prefix on standard output prior to the line of text so that you can verify that it all works.
    Note that the process numbers used above are not the numbers used for network addressing, they are just for the purpose of documentation. Your interprocess communication mechanism should use the UNIX process ID.