Assignment 12, due Apr. 27

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

On every assignment, write your name legibly as it appears on your University ID and on the class list! Assignments are due at the start of class on the day indicated (usually Friday). Exceptions 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, either in class or in the instructor's mailbox. Never push late work under someone's door!

Notice: This entire homework is in preparation for the final machine problem:

  1. Background: Read the man pages for shmat, shmget, mmap and clone system calls.

    a) These can be used to create a situation where a parent process and a child process share memory with each other (in some cases, you may also need to use fork or other system calls to set this up), but there are differences that are the result of the way Unix/Linux evolved. Identify the three basic alternatives, and for each, describe the most significant thing it does that is different from the others. (1 point)

    b) You have two functions, call them a() and b(); you want these functions to share a read-write memory area of at least s bytes, pointed to by the pointer p. which of the 3 methods described above leads you to the simplest way to do this? Give a short argument justifying your conclusion, without actually giving code; all you need to do is explain what makes one or the other solution more difficult than the one you select. Note that you may want to start on part c first before commiting yourself to an answer. (1 point)

    c) Give a skeleton of the code for the solution you selected in part b. As a skeleton, this needs to say what functions to call in what order, but it need not contain all the declarations and may simplify some functions by leaving out details of some parameters, so long as you include all of the key control structures. (1 point)

Machine Problem 6, Due April 30

Write code for a pair of processes that communicate through shared memory.

In sum, your program should behave in much the same way as the command-line cat command when the latter is run with no arguments, except that your program, gratuitously, uses multiple processes communicating through shared memory. You may use any synchronization method you want, although it is strongly recommended that you emphasize minimizing the complexity of your code. You may find the sem_overview man page helpful.

Submit your solution as file mp6.c in the usual manner. Half the score will be based on the quality of your code, half on its execution.