CS 3733 Operating Systems, Spring 2003 Assignment 5

This is a preliminary announcement for those that want to get started early.


Due Thursday, April 24, 2003

This is the final assignment. On Thursday, April 24 we will meet in the lab and you will demonstrate your project to me.

Create a directory called assign5 for this assignment. Put each part of this assignment in a different subdirectory.


Part 0:
Get this tar file and compile the code. Run the bidirectional client, client2, and server, server2, and make sure they can communicate.

Part 1:
Modify the readex program of Assignment 4, Part 1 so that it catches SIGCHLD instead of SIGUSR1. The signal handler should just print a message indicating that the signal was caught.

You can test this program the same way you tested the programs from Assignment 1. Each time a child finished, the signal handler should print a message.

Part 2:
Write a function:
int connect_and_send(char *host, int port, char byte, int recvflag);
that makes a connection to the given host on the given port and sends a single byte (the third parameter) to that host. If recvflag is not zero, read one byte from the remote host. In any case, close the connection. Return 0 on success (no error) or return -1 with errno set if an error occurs. Make sure you close the connection even if an error occurs.

Eliminate all waiting for children from readex of Part 1 and eliminate all tests to limit the number of active processes. The program now takes two command-line parameters, a host and a port number. After each line is read, call connect_and_send with the given host and port as the first two parameters. The third parameter is 'A' and the last parameter is 1. This version of readex will only start new processes after getting "permission" from the remote server. Modify the signal handler so that it does a nonblocking waitpid in a loop until it does not return a pid. Each time it returns a pid, call connect_and_send with byte 'B' and flag 0. Test this program using bidirectional server, server2 from Part 0. You can have the server send a single byte pushing one key followed by CTRL-D. You can close the connection with another CTRL-D.

Part 3:
Write a program, license_manager.c that will act as a license manager. It takes two command-line parameters, a port number and a number of licenses. The server does the following:

Test this server by writing a client program, servertester, that takes three command-line arguments, a host name, a port number and a value. It makes a connection to the given host and sends a 1-byte value to the host equal to the last command-line parameter. It tries to read a 32-bit value in network byte order. If it receives this value is displays it with a message indicating that it is the number of licenses available. If the connection is closed before the value is read, the program just prints a message indicating whether it made the connection. In either case, the program exits after printing the message.

Part 4:
Modify readex from Part 2 to send -1 instead of 'A' and 1 instead of 'B'. Test this readex program with the server of Part 3.


Handing in your program

Use this cover sheet.
For Part 1, test your readex program with
    readex 2 < infile1
Turn in the output produced by readex.

For Part 2, run readex with input coming from infile1 on one machine and server2 on another. Enter input to server2 as follows:

For Part 3, start license_manager on one machine with a command-line argument of 3. On another machine run servertester several times as follows and turn in the output produced. Assuming the license_manager was started on machine x with port y, run:
    servertester x y 0
    servertester x y -1
    servertester x y 0
    servertester x y 1
    servertester x y 0
    servertester x y 1
    servertester x y 0

If you have Part 4 working, be prepared to demonstrate readex with license-manager in the lab on April 24. When you get to the lab on April 24, check the course wbe site for instructions on demonstrating your program. Hand in your assignment when you demonstrate it to me. You may leave after you have demonstrated your Part 4.
If Part 4 is not working, hand me your assignment in the lab on April 24. You are then free to leave.