CS 3733 Operating Systems, Spring 2002 Assignment 4


Due Thursday, April 4, 2002


This is a short assignment to give you some practice using signals and to give you some time (if you need it) to get your Assignment 1 ready for Assignment 5.

In this assignment you will add signal processing to your Assignment 1.

Part 0
Get Assignment 1 working correctly. If you got full credit on Assignment 1, there is probably nothing you need to do here.

If your program did not pass the tests from Part 5 of Assignment 1, make the necessary modifications and run it again.

If your program passed the tests, but you did not receive full credit, make the modifications indicated in my comments on your assignment and rerun the test program.

Part 1
Start with all of the files from Part 5 of Assignment 1. Modify the command_logger.c function so that it contains a function, void my_handler(int signo), that can be used as a signal handler. When this function is called, a message is printed to standard error giving the total number of input lines processed, the total number of valid GET commands containing a server, the total number of valid GET commands without a server, and the total number of output bytes logged.

Your command_logger will have to keep this data in global variables so that it is accessible to the signal handler. Think about possible ways of doing this without using global variables. You may assume that fprintf is async-signal safe.

Modify logger_test so that it starts by printing its process ID and catches SIGUSR1 using my_handler.

You will have to modify the readline in logger_test because ot will exit when a signal interrupts the getchar call. This call is not signal-friendly. You should replace it with a call to read using STDIN_FILENO. Make sure that the read is restarted when a signal comes in and that your program still terminates on end of file.

Test your program in two windows. In one window, start logger_test with output redirected to a file. Type lines to logger_test.

From the other window, periodically send SIGUSR1 signals to your program. When the signals are received, the information should appear in the first window. The signals should not interfere with the logging to the file.

Run your logger_test without redirection and 6 lines of input, a least one having and invalid GET, at least one having a server, and at least one without a server. Then use CTRL-D for end of file. From the other window, send a SIGUSR1 signal before the first input line, after the third line, and after the sixth line before the end of file.

Use cut-and-paste to gather the output to be printed out and turned in.

Make sure you run lint on your programs. The files logger_test, parse_initial, and command_logger should be linted together.

Use this cover page.