Homework 3: Inter Process Communication (IPC):
Shared memory & Message Queues.
Assignment Day | January 31, 2018 (Wednesday) |
Due Date | February 06, 2018 (Tuesday before class) Note that the project is due later in the week, Friday. |
Email (time stamp), Typed Hardcopy are required and submit code to nike via csx730. |
Question 1: Shared Memory (15 pts):
Write a simple a program (starting programming snippets are available here and here) where 3 processes, A, B and C synchronize via polling on a shared location in memory called "position 1".
Process A prints out strings from shared memory of two other separate processes, B and C. Process A synchronizes by polling a location, it polls or 'wait' by polling until B and C finish writing their strings to memory.
Here is the sequence of events that needs to be implemented:
- Process A writes to position 1 (it writes "1") in memory and then waits until B and C completes.
- Process B writes the string "shared" into memory then signals A & C that it is complete by writing into memory position 1 (it signals by writing "2", note B should wait to write into position 1 until after process A writes into position 1 in memory)
- Process C writes the string "memory" into memory and then signals A that it is complete by writing into memory position 1 (it signals by writing "3", note C should wait until process B writes into position 1 in memory). A diagram of the events is depicted below. Memory position 1 in memory is denoted in pink (there are 3 pink boxes to demonstrate the 3 values of position 1 in memory).
Submit a hardcopy of your code (make sure it is readable). We will grade this on conciseness and correctness by inspecting your submitted code.
Question 2: Shared Memory (4 pts)
How are shared memory segments finally destroyed? What UNIX utility can be used to to determine whether a memory segment has been destroyed or not?
Question 3: Message Queues (6 pts)
Review the programs (spock.c and kirk.c) that we discussed in class Tuesday on Beej's Message Queue section and also read Beej's discussion (link is here). Code is also available for copy (here and here).
Answer (or discuss) Beej's questions (also listed below):
a) Discuss and evaluate what happens when you're running both in separate windows and you kill one or the other.
b) Discuss what happens (and why) when you run two copies of kirk.
c) Discuss what happens (and why) when your run two copies of spock.