Unix Systems Programming: Lab 7

Due:          Wednesday, November 17, 2010 @ 5:00 pm.


Purpose and Rationale

The purpose of this lab is to introduce students to System V IPC through semaphores, message queues and shared memory.

Resources

FAQ (submission instructions and other useful stuff)
If you are not in our course email list, please subscribe to the cspp51081 email list here:
        http://mailman.cs.uchicago.edu/mailman/listinfo/cspp51081
You will also find the course FAQ containing useful information for this assignment.

Lecture 7 is the primary source for information on System V IPC. You can find additional information in the manpages, online, as well as the following sources:

All work should be done on a machine in the department's Linux cluster. You can refer to ssh for more information on how to log into a remote machine.

Getting Started

In this assignment you will choose one of three options:

Deliverables

Each assignment has specific directions on how to submit. Follow the procedure carefully, correct delivery of your work is worth 5 points. Follow the 4 steps below.

  1. Create a directory:
           username.lab7
  2. You will have one directory to store your assignment (except for the last option):
  3. Each exercise will provide more details on the files you will need to provide in this directory.
  4. When you are finished with your assignment you will create a compressed archive file using tar (this utility stores your directory as a single file, then compresses its size.)
           tar -czvf   username.lab7.tgz   username.lab7
  5. You will email your file to our grader as an attachment. I will send an aknowledgement that your assignment has been received.

  6. To soner@cs.uchicago.edu
    Attachment  username.lab7.tgz
    Subject  CSPP51081

LAB 7

  1. Client-Server Communication using Message Queues


    Problem Statement:

    Two processes, client and server, communicate via two message queues "Up" and "Down".

                            Server

                            ^     |
                       Up |       v Down

                            Client

    The client reads a message from the standard input and sends it to the server via the Up queue, then waits for the server's answer on the Down queue. The server is specialized in converting characters from lower case to upper case and vice versa. Therefore, if the client sends the message "lower case" via the Up message queue, the server will read the message, convert it, and send "LOWER CASE" via the Down queue. When the client receives the message from the server, it prints it out.  You may assume the maximum size of any message is 256 bytes.

    Multiple clients must be able to connect to the up and down queues.  However, what happens if one client puts a letter to convert on the system and another client is waiting for it's response from the queue?  There are different ways to handle this, but you should handle this using typed messages.  Each client has a particular client number based on the last 4 digits of its process ID.  Use this 4-digit number as the client identifier, and use typed messages on the queue so that each client can always be sure to receive the letter that it is waiting on to be converted.
     

    What to do:

    Implement the client and server from the scenario above.

    Deliverables

    This will complete step 2 of Deliverables:

    1. Create a directory ex1
    2. This directory will contain three files:
      • client.c
      • server.c
      • Makefile: which must will build your client and server. It must also contain a target clean.

    Grading

    This assignment is 25 points, including 5 points for correct submission. Your Server must be able to handle multiple clients correctly to recieve full credit.

  2. The Consumer-Producer Problem using Shared Memory


    Problem Statement

    Write 2 programs, producer.c implementing a producer and consumer.c implementing a consumer, that do the following:

    What to do

    Look on these examples of shared memory usage: shm_server.c creates a shared memory segment and writes "hello world" into it. shm_client.c reads and prints out the content of the shared memory segment. The way to compile and run the examples is:

    hangao@gawaine:LAB7% gcc -o shm_server shm_server.c
    hangao@gawaine:LAB7% gcc -o shm_client shm_client.c

    hangao@gawaine:LAB7% shm_server 1234 &
    [1] 27633
    Try to create this segment
    shared memory content: hello world

    hangao@gawaine:LAB7% shm_client 1234
    Trying shared memory 1234
    shared memory: 1152
    shared memory: 0x40016000
    shared memory content: hello world
     

    Deliverables

    This will complete step 2 of Deliverables:

    1. Create a directory ex2
    2. This directory will contain three files:
      • producer.c
      • consumer.c
      • Makefile: which must will build your client and server. It must also contain a target clean.

    Grading

    This assignment is 25 points, including 5 points for correct submission. Your Producer will be run with multiple consumers. Your product count must not drop below 0 or rise above 5. Your program is not responsible for keeping the consumers happy: as more consumers are added, there will be more trips down an empty aisle.

  3. Synchronization of Consumers and Producers using Semaphores


    Problem Statement

    You should read Exercise 2 carefully first. I recommend you implement exercise 2 before beginning the Bonus Problem.

    We will make three modifications to Exercise 2:

    What to do

    Start by making sure you have a program which works for exercise 2. Now, up the ante, slowly and see if you can maintain sanity. Try each addition above to your program and see how it behaves. If your program has difficulty try to fix the problem, if you cannot analyze where you think the problem lies. Credit for this problem will not be solely based on successful performance, but on careful observation of your program's performance and analysis of difficulties you may be having controling behavior with semaphores. Keep a log of what you have and tried, and how your program has performed. This will be submitted as a README file.

    Deliverables

    This will complete step 2 of Deliverables:

    1. A directory ex2 with your files from exercise 2
    2. Create a directory bonus
    3. This directory will contain four files:
      • producer.c
      • consumer.c
      • Makefile: which must will build your client and server. It must also contain a target clean.
      • README: This should state how you have implemented your semaphare, whether your consumers can be greedy, your producers overly diligent, and how your program has fared under varying conditions. Careful notes will help your score here.

    Grading

    The bonus is worth 10 points total. Partial credit will be given. The purpose of this bonus is for you to kick back and see how System V IPC fairs under the strenuous conditions imposed by the Producer/Consumer Problem. Incremental points will be given, and success judged as much by your observations as by your program's performance. Your README file will be important here.


Atilla Soner Balkir