CS 3733 Operating Systems, Spring 2003 Assignment 4


Due Thursday, April 10, 2003

This assignment will prepare you for Assignment 5 and give you some experience using signals.

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


Part 0:
Get Part 3 of Assignment 1 working correctly. If you got full credit on Assignment 1 and believe that it is already working correctly, there is nothing for you to do on this part other than copying the files to a new directory. Make sure the output generated by the tests described in Part 3 of Assignment 1 is correct. You might want to read over my comments on the web concerning Assignment 1.

Part 1:
Rewrite your readline so that it works correctly with signals. If a signal comes in while your readline is blocked, the readline should restart the blocked call.

Add a signal handler to your Part 0 readex code. The signal handler should just print a line in the form:
     Signal number n received.
Where n keeps a count of the number is signals that have been received. You may assume that fprintf is safe to use in a signal handler.

Set up your program to catch SIGUSR1 and use this signal handler. Your readex should now start by printing your name and its process ID.

Test your program in two windows, one to run readex as you did in Part 3 of Assignment 1, and one to send it SIGUSR1 signals. Test your program and save the output generated by readex. Your output should show that you have thoroughly tested your program and that the signals did not interfere with the execution of your program.

Part 2:
Modify the signal handler and make other modifications to allow the signal handler to display the number and names of the programs (with their command line arguments) that your program thinks are currently running. Do not display ones that have completed. Pay particular attention to avoiding buffer overflows. You may assume that if the input line representing the name of the program (with arguments) is greater than 100 bytes, this is an error and the program should not be run. Test your program as you did in Part 1.

Part 3: (extra credit)
Remove the restriction of the maximum size on the length of the input line. This will involve rewriting the readline function and modifying the list of running programs. Pay special attention to avoiding buffer overflows and memory leaks.

Part 4: (extra credit)
Have the signal handler also display a separate list of the programs that have completed execution. Do not make any assumptions about the length of this list.

Part 5: (extra credit)
In your signal handler, use only those functions that are listed in Table 5.3 of PUP.

Note that the three extra credit parts are independent of each other. No extra credit will be given if Part 2 is not working correctly.


Turning in the assignment.
Use the cover sheet and include all source files, lint output, and test output asked for on the cover sheet. For each program that you write you should run lint and save the output generated. You should understand all lint warning, and correct your code to remove warnings that should not be there. You should not have any implicitly declared to return int messages. Turn in the hard copy on the due date.