The purpose of this lab is to introduce students to System V IPC through semaphores, message queues and shared memory.
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.
In this assignment you will choose one of three options:
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.
ex1
: If you
are submitting exercise 1ex2
: If you
are submitting exercise
2, onlyex2
and an additional directory
bonus
.To | soner@cs.uchicago.edu |
Attachment | username.lab7.tgz |
Subject | CSPP51081 |
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]);
}
This will complete step 2 of Deliverables:
ex1
client.c
server.c
Makefile
: which must will
build your client
and server. It must also contain a target clean.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.
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
This will complete step 2 of Deliverables:
ex2
producer.c
consumer.c
Makefile
: which must will
build your client
and server. It must also contain a target clean.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.
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:
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.
This will complete step 2 of Deliverables:
ex2
with your
files from exercise 2bonus
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. 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.