CS 3733 Operating Systems, Fall 2002 Assignment 4


Due Thursday, November 14, 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. You should use a single makefile to compile and lint the various parts of this assignment. Add to the makefile as you start each new part.

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 4 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
Write a program, signal_sender that takes 1 command line argument, a process ID. It reads lines from standard input and writes them out to standard output. If a line contains exactly 7 bytes starting with "signal", instead of sending the line to standard output, it sleeps for 1 second, sends a SIGUSR1 signal to the process whose PID was given as the command line argument and sleeps for 1 second again before sending any additional lines. This program only needs to handle lines of at most 1024 bytes in length, and should exit gracefully if a longer line is entered. Test this program.

Part 2
Start with all of the files from Part 4 of Assignment 1. Modify the command_logger.c function so that it keeps track of the following counts in global variables:

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 counts described above. The output should appear in a table with a heading and a line for each value.

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 it 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 using signal_sender from Part 2. Design an input file containing 10 lines with the following properties:

Store the lines in a file, infile. Add lines to the file so that it can be used with signal_sender as input to your new command_logger. Signals should be sent before the first line, adter the third line, after the 5th line, after the 7th line, and after the 10th line. These line number refer to the lines being sent to command_logger. Your input file will contain 15 lines, with the last line being "signal".

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.