The purpose of this lab is to allow students to become comfortable with System V IPC using semaphores, message queues and shared memory.
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.
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 |
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.
Implement the client and server from the scenario above.
hangao@gawaine:LAB7% server &
hangao@gawaine:LAB7% client
Insert message to send to server: message
Msg processed: MESSAGE
Insert message to send to server: UPPER CASE
Msg processed: upper case
client.c
and server.c
that implement the behavior explained above. You may want to use this
conversion function for the server code: /* convert upper case to lower case or vise versa */
void conv(char *msg, int size)
{
for (i=0; i<size; ++i)
if (islower(msg[i]))
msg[i] = toupper(msg[i]);
else if (isupper(msg[i]))
msg[i] = tolower(msg[i]);
}
Write 2 programs, producer.c
implementing a producer and consumer.c
implementing
a consumer, that do the following:
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
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:
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.
Carefully follow the 3 steps below. NOTE: Each assignment has specific directions on how to submit.
For submitting exercise 1 ex1
client.c
server.c
Makefile
: which must will
build your client
and server. It must also contain a target clean.
For submitting exercise
2
ex3
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. To | Aiman Fang (aimanf@cs.uchicago.edu), Zhixuan Zhou(zhixuanzhou@cs.uchicago.edu) |
Attachment | username.lab7.tgz |
Subject | CSPP51081-lab7 |