Last Updated: 2021-03-28 Sun 17:15

CSCI 4061 HW10: IPC Message Queues and Server/Clients



1 Rationale

Basic IPC mechanisms are important to allow unrelated processes to cooperate. The three standard types are Semaphores, Shared Memory, and Message Queues. This HW illustrates the use of POSIX Message Queues to solve a similar server/client problem from a previous HW and contrast that solution.

1.1 Associated Reading

  • Manual Page Entries on POSIX Message Queues such as man mq_overview.
  • Stevens & Rago does not discuss POSIX message queues instead covering older System V message Queues in 15.6 and 15.7; concepts are similar but the specific functions and capabilities of these are significantly different from POSIX message queues.
  • Stevens & Rago 15.11 on Client/Server Properties and arrangements of them with FIFOs (in 15.5) are also informative.

1.2 Grading Policy

Credit for this HW is earned by taking the associate Quiz which is linked under Gradescope. The quiz will ask similar questions as those that are present in the QUESTIONS.txt file and those that complete all answers in QUESTIONS.txt should have no trouble with the quiz.

See the full policy in the syllabus.

2 Overview

2.1 Codepack

The codepack for the HW contains the following files:

File Description
QUESTIONS.txt Questions to answer
Makefile Makefile to build programs below
em_client_fifo.c Code from a previous HW for lookup using FIFOs
em_server_fifo.c Code from a previous HW for lookup using FIFOs Script to run server with many clients
em_server_mq.c Problem 1: Small server to look up email based on name using message queues
em_client_mq.c Problem 1: Client to connect to server with a name to get an email using message queues Script to run server with many clients
faulty_em_server_mq.c Problem 2 faulty server
faulty_em_client_mq.c Problem 2 faulty client Script to run server with many clients

2.2 Programs

There are 3 sets of programs in this HW each fulfilling the same role as the email lookup server/client from the last HW.

  1. Last HWs FIFO version
  2. A new version which uses POSIX message queues which is explored in Problem 1
  3. A message queue version which is faulty explored in Problem 2.

As before, running these programs interactively requires 2 terminals, 1 for server and 1 for client as in the below.

SERVER 32443: starting up
SERVER 32443: created message queue, listening for requests
SERVER 32443: received request {client_queue_name='/32557_q' query_name='George Karypis' }
SERVER 32443: opening client queue '/32557_q'
SERVER 32443: writing email '' for query_name 'George Karypis'
SERVER 32443: closing connection to queue '/32557_q'
SERVER 32443: received request {client_queue_name='/32594_q' query_name='Mats Heimdal' }
SERVER 32443: opening client queue '/32594_q'
SERVER 32443: writing email 'NOT FOUND' for query_name 'Mats Heimdal'
SERVER 32443: closing connection to queue '/32594_q'

> ./em_client_mq 'George Karypis'
CLIENT 32557: sending request: {client_queue_name='/32557_q' query_name='George Karypis' }
CLIENT 32557: awaiting server response
CLIENT 32557: response for name 'George Karypis' is email ''

> ./em_client_mq 'Mats Heimdal'
CLIENT 32594: sending request: {client_queue_name='/32594_q' query_name='Mats Heimdal' }
CLIENT 32594: awaiting server response
CLIENT 32594: response for name 'Mats Heimdal' is email 'NOT FOUND'


Also, each script has a script that allows a "simulation" of an arbitrary number of clients to be run as in

# run with 10 clients
./ 10
SERVER   686: starting up
SERVER   686: created message queue, listening for requests
CLIENT   689: sending request: {client_queue_name='/689_q' query_name='Christopher Jonathan' }
CLIENT   689: awaiting server response
SERVER   686: received request {client_queue_name='/689_q' query_name='Christopher Jonathan' }

3 What to Understand

Ensure that you understand

  • The basic semantics of message sending and receiving
  • Similarities between Message Queues and FIFOs
  • Difficulties that arise when cooperating programs can act on a shared resource in an arbitrary order which makes concurrent programming tough.

4 Questions

Analyze these files and answer the questions given in QUESTIONS.txt.


                            HW 10 QUESTIONS

- Name: (FILL THIS in)
- NetID: (THE kauf0095 IN

Write your answers to the questions below directly in this text file.
HW quiz questions will be related to the questions in this file.

PROBLEM 1 `em_server_mq.c' and `em_client_mq.c'

  Examine the source code for `em_server_mq.c' and
  `em_client_mq.c'. Compile and run these codes running the server in
  one terminal with clients in another terminal. You may also try
  `./ 100' which will start the server and 100
  clients to communicate with it.


  After gaining familiarity with the code, describe the lines of code
  which are used to create POSIX Message Queues.
  - What specific system calls are used to create/access message queues?
  - Which of the server/clients create message queues?
  - How does this compare to the previous FIFO version in the code pack?


  Describe the sending and receiving functions used in the server/client
  to interact with message queues.
  - What arguments are required for the sending function?
  - What arguments are required for the receiving function?
  - Does the same data type of message go from client to server as from
    server to client?
  - What are the equivalent send/receive functions in the FIFO version
    of the server?


  Overall, contrast the protocol and architecture of the POSIX Message
  Queue version of the server/client with the FIFO version studied in
  last week's lab.  Are there any major similarities or difference
  between these two?

PROBLEM 2: The Faulty Server

  Examine the provided `faulty_em_server.c' and `faulty_em_client.c'
  which use POSIX Message Queues for communication.  Compile these via
  `make' and run the server in a terminal with clients in another
  terminal. This should appear to work normally. However,
  `./ 100' which will launch the server with 100
  clients will report errors. This problem determines why.


  Examine the architecture for communication that is used between
  `faulty_em_server.c' and `faulty_em_client.c'.
  - How many message queues are there?
  - What appears to be the protocol for communication?


  Run the "simulation" script for the faulty server and examine the
  | > ./ 100
  To ease the analysis, the script gives clients the expected email
  associated with each name and the client verifies if it gets the
  correct email or reports and ERROR.

  For small runs such as with 10 clients, there may be no errors but for
  larger runs like 100 there are always errors.

  - Construct an argument as to why the protocol used in this version is
    "faulty" as the name suggests.
  - Is this issue specific to Message Queues or would FIFOs have similar
    problems with the faulty protocol?
  - What concurrency issues are present that are not a problem in the
    previous message queue/FIFO versions of the server/client?

Author: Chris Kauffman (
Date: 2021-03-28 Sun 17:15