CS 3733 Operating Systems, Spring 2004 Assignment 5

Due Tuesday, April 27, 2004, before class

In this assignment you will rewrite the programs from Assignment 3 so that they communicate over a network. Use the port numbers that were assigned to you for recitation number 9.

Part 0:
If you haven't already done so, finish Parts 8 and 9 of assignment 3. Write an explanation of what you had to fix, how you tested the program and what results you got.

Part 1:
In this part you will write a network client called program_network_client. Start with one of the client network programs from Chapter 18 of USP. The description below is very similar to that of program_client of Part 8 of Assignment 3. The program takes two command line arguments, a host name and a port number.

  1. Print a message to standard error showing your name, something like:
    This program was written by ...
  2. Check to make sure the program has exactly two command line arguments and print a usage message and exit if it does not.
  3. In future parts, if an error occurs, print an appropriate message and exit the program.
  4. Open a connection to the given server on the given port.
  5. Nothing to do here.
  6. Use read_int_as_line to read an integer from the network and then read that many bytes from the network and send them to standard output.
  7. Read an integer from standard input, as in Assignment 1, Part 10.7.
  8. Send that integer to the network as a line using send_int_as_line.
  9. Use read_int_as_line to read an integer from the network and then read that many bytes from the network and send them to standard output.
  10. Print a message to standard error indicating success and exit the program.
You should be able to test this program with the bidirectional server from chapter 18 of USP. Write an explanation of how you tested the program and what results you got.

Part 2:
Write a main program called program_network_server that takes two command line arguments: a filename and a port number. The first argument will be referred to as infile. This program will be similar to the program_server from Assignment 3, but it will use a network connection rather than named pipes. This should be a parallel server. It should fork a child process to handle the connection.

  1. Print a message to standard output showing your name, something like:
    This program was written by ...
    This program will print all messages to standard output. Nothing should be written to standard error. Once the program gets past item 4 below, the original parent should never exit.
  2. Check to make sure the program has exactly two command line arguments and print a usage message and exit if it does not.
  3. Open infile and read it into memory.
  4. Test to see that infile only contains valid program lines. If not, print a message and exit.
  5. Wait for a network connection on the given port.
  6. When a connection is made, fork a child to handle the communication. The parent then goes back to accept additional requests after handling zombie processes.
  7. Send the size of infile as a line using send_int_as_line and then send infile, both going to the network.
  8. Get an integer from the network using read_int_as_line. If this corresponds to a program number of one of the lines in infile send the corresponding file to the network by first sending the size of the file and then the file itself. Use send_num_bytes so that you do not have to read this entire file into memory.
  9. Print a message indicating success and exit the child program.
Test this program with the client of Part 2. They should be able to communicate on different machines. Write an explanation of how you tested the program and what results you got.

Note: You should only have to read in the infile once, no matter how many requests are mad from clients.

Part 3: (extra credit)
Put the code for this part of the assignment in a part3 subdirectory. Rewrite the server program of part 2 to use threads rather than child processes. Keep track of the number of requests for each program and display this in a message containing when a SIGUSR1 signal is received by the server. Have the server display its process ID when it starts so that you can send it a signal.

Make sure you understand where synchronization is necessary and be sure to use only async-signal safe functions inside any signal handler. Make sure that the other parts of the program work correctly in the presence of signals.

Write an explanation of how you tested the program and what results you got.

Part 4: (extra credit)
Only attempt this is you have Part 3 working correctly. Put the code for this part of the assignment in a part4 subdirectory. Rewrite the server from Part 3 so that instead of handling signals, it sends a message giving the number of requests for each program to a remote host that makes a connection on the port number which is one greater than the command line argument. The message that is sent should be self-explanatory and suitable for printing without modification. Do this with a separate thread. Be careful about synchronization.

You can test this with your client from Part 1 and the client2 program from USP. Write an explanation of how you tested the program and what results you got.

Handing in your program (modified):
Use this cover sheet. Consecutively number all of the other pages you turn in. Each page that contains your work should have a number on it.

We will be meeting in the Sun lab during the regularly scheduled class time on Tuesday, April 27.

If your client and server are not working well enough to be tested in the lab, just hand in your assignment to me during the lab time. Be sure that you have filled in in the bottom of the cover sheet explaining exactly what progress you have made on this assignment.

If you think your programs are working correctly, you must demonstrate them to me in the lab. Create two fresh directories, one containing only the client executable and one containing only the server executable. Open a terminal window for each directory.

In the directory containing your server, execute the following command:
/home/srobbins/assign5/makelinks
This will make 4 symbolic links in your directory to files that will be used by your server. Be prepared to start your server using program_file as the first command line argument.

Find someone else in the class who is sitting at a nearby machine. Agree on port numbers to use. You will each demonstrate your client with the other person's server. You will be given the input files to be used at the time the programs are tested.

If you have done the extra credit also do the following: