Unix Systems Programming: Lab 7- System V IPC:  message queues, semaphores, shared memory

Due:          Tuesday, February 25, 2014 @ 5:00 pm.


Purpose and Rationale

The purpose of this lab is to allow students to become comfortable with System V IPC using semaphores, message queues and shared memory.

Resources

FAQ (submission instructions and other useful stuff)
Please look at lab7 FAQ for useful material on unnamed and named pipes.

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.

Marks Distribution

This lab has three parts:

Exercise 1: Message Queues 4 points
Exercise 2: Shared Memory 4 points
Exercise 3: Shared Memory with Semaphores 4 points
TOTAL 12 points

LAB 7

EXERCISE 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.

  • EXERCISE 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
     
  • EXERCISE 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 this exercise.

    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

    Carefully follow the 3 steps below. NOTE: Each assignment has specific directions on how to submit.

    1. There will be three directories each corresponding to a separate problem.
    2. When you are finished with your directory 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

    3. You will email your file to our graders as an attachment. They will send an acknowledgement that your assignment has been received.

    4. To  Aiman Fang (aimanf@cs.uchicago.edu), Zhixuan Zhou(zhixuanzhou@cs.uchicago.edu)
      Attachment  username.lab7.tgz
      Subject  CSPP51081-lab7