Last Updated: 2021-03-23 Tue 12:16

CSCI 4061 HW09: FIFOs servers Server and Clients

CODE DISTRIBUTION: hw09-code.zip

  • Download the code distribution every lab
  • See further setup instructions below

CHANGELOG: Empty

1 Rationale

FIFOs provide a nice way for two unrelated processes to communicate. However, if multiple processes wish to work on a FIFO, some sort of protocol must be used to ensure that their communication is coordinated and does not result in problems such as deadlocks or stalls. This lab explores both these issues.

1.1 Associated Reading

Ch 15.1-5 of Stevens & Rago discusses pipes, FIFOs, and simple client-server models

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 lab contains the following files:

File Description
QUESTIONS.txt Questions to answer
Makefile Makefile to build programs below
em_server.c Small server to look up email based on name
em_client.c Client to connect to server with a name to get an email
run_simulations.sh Script to start server and arbitrary number of clients

2.2 Programs

Compile and run the em_client and em_server programs. To do so interactively, you will need two terminals, one for the continually running server and one for the client. Running them will produce something like the following:

# SERVER
> ./em_server
SERVER 14841: starting up
SERVER 14841: created new requests.fifo, now opening it
SERVER 14841: opened requests.fifo, listening for requests
SERVER 14841: received request {client_fifo='14842.fifo' query_name='Chris Kauffman' }
...

-------
# CLIENT TERMINAL
> ./em_client "Chris Kauffman"
CLIENT 14842: sending request: {fifo_file='14842.fifo' query_name='Chris Kauffman' }
CLIENT 14842: opening '14842.fifo'
CLIENT 14842: fifo opened, awaiting server response
CLIENT 14842: response for name 'Chris Kauffman' is email 'kauffman@umn.edu'

> ./em_client "Amy Larson"
CLIENT 14882: sending request: {fifo_file='14882.fifo' query_name='Amy Larson' }
CLIENT 14882: opening '14882.fifo'
CLIENT 14882: fifo opened, awaiting server response
CLIENT 14882: response for name 'Amy Larson' is email 'larson@cs.umn.edu'

> 

You can also simulate a larger number of clients connecting to a server using the run_simulations.sh program as below. Ensure you do not servers running in this case.

# run the server and start up 10 clients to connect to it
> ./run_simulation.sh 10
SERVER 14893: starting up
SERVER 14893: created new requests.fifo, now opening it
SERVER 14893: opened requests.fifo, listening for requests
CLIENT 14895: sending request: {fifo_file='14895.fifo' query_name='Chris Kauffman' }
CLIENT 14895: opening '14895.fifo'
CLIENT 14895: fifo opened, awaiting server response
SERVER 14893: received request {client_fifo='14895.fifo' query_name='Chris Kauffman' }
SERVER 14893: opening client FIFO '14895.fifo'
SERVER 14893: writing email 'kauffman@umn.edu' for query_name 'Chris Kauffman'
CLIENT 14895: response for name 'Chris Kauffman' is email 'kauffman@umn.edu'
...

3 What to Understand

Ensure that you understand

  • How FIFOs are created by the server and used by clients to communicate with the server and receive information without being a child process
  • Some basic ideas of how a protocol determines who does what when in order for cooperating parties to avoid conflicts and errors

4 Questions

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

                           _________________

                            HW 09 QUESTIONS
                           _________________


- Name: (FILL THIS in)
- NetID: (THE kauf0095 IN kauf0095@umn.edu)

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.c'
=======================

A
~

  Examine the source code for `em_server.c'. Describe the
  `requests.fifo' item that it creates.  Resolve theses specific items
  1. What system call is used initially to delete any existing version
     of `requests.fifo'?
  2. What system call is used to create `requests.fifo'?
  3. What system call is used to set up reading from `requests.fifo'?


B
~

  In the main `while()' loop of the server, describe how the server
  handles requests from the client.
  1. What C data type represents the requests from clients and what
     parts does it have?
  2. How does the server use the request data to search for a name/email
     association?
  3. How does the server use the request data to communicate back to the
     client?


PROBLEM 2 `em_client.c' and Protocol
====================================

A
~

  Examine the code for `em_client.c'. Describe the steps that it
  performs to contact the server to make a request and then receive the
  response.  Describe how system calls are used in this process.


B
~

  Describe the overall Protocol of communication of between the server
  and client. Which entity is responsible for creating, reading, and
  writing each FIFO at what time.


C
~

  Use the provided script `run_simulation.sh <N>' to launch start a
  server and run a specified number of clients such as 5 as below
  ,----
  | > ./run_simulation.sh 5
  | SERVER 14205: starting up
  | SERVER 14205: created new requests.fifo, now opening it
  | SERVER 14205: opened requests.fifo, listening for requests
  | CLIENT 14208: sending request: {fifo_file='14208.fifo' query_name='Christopher Jonathan' }
  | CLIENT 14208: opening '14208.fifo'
  | ...
  | SERVER 14205: closing connection to fifo '14212.fifo'
  | CLIENT 14211: response for name 'Dan Knights' is email 'knights@cs.umn.edu'
  | CLIENT 14212: response for name 'George Karypis' is email 'karypis@cs.umn.edu'
  | > 
  `----
  Examine the output for this run along with running the simulation
  several more times with different numbers of clients.

  Explain why there never seems to be any problem with multiple clients
  overwriting data associated with each other particularly in the
  `requests.fifo' and the client responses.


PROBLEM 3: Pitfalls
===================

A
~

  Compile the server/client with `make' and run the server via
  ,----
  | > ./em_server
  `----
  Note the output that it prints. Then kill the server, perhaps with a
  C-c interrupt signal.

  Edit the `em_server.c' code to use the line marked `ALTERNATE
  OPEN'. You should comment on the preceding `open()' line to get
  ,----
  | // int requests_fd = open("requests.fifo", O_RDWR);               // open FIFO read/write to avoid blocking
  | int requests_fd = open("requests.fifo", O_RDONLY);             // ALTERNATE OPEN: read only
  `----

  Recompile and re-run `em_server' and explain why the output of the
  server changes in this case. To understand the change in output, you
  may need to review what happens when a process opens only one end of a
  pipe/FIFO.


B
~

  With the ALTERNATE OPEN line in use (uncommented), start the
  `em_server' which should appear to be 'waiting' for something. Then in
  a separate terminal, run `em_client'.  Describe if the client and
  server behave differently than when the original `open()' line was in
  use by the server.


C
~

  With the ALTERNATE OPEN line in use (uncommented), run the
  `run_simulation.sh 5' script a few times until it appears to stall and
  fail to complete.

  Examine the output of the simulation run carefully and find a line
  involving the server that gives some hints as to why the simulation
  fails. Show that line below.


D
~

  Do some careful thinking, reading, and exploration and explain why the
  ALTERNATE OPEN line creates a flaw in the server/client protocol that
  is NOT present in the original version.

5 Again, What to Understand

Ensure that you understand

  • How FIFOs are created by the server and used by clients to communicate with the server and receive information without being a child process
  • Some basic ideas of how a protocol determines who does what when in order for cooperating parties to avoid conflicts and errors

Author: Chris Kauffman (kauffman@umn.edu)
Date: 2021-03-23 Tue 12:16