Unix Systems Programming: Lab 4
Due: Wednesday, October 27, 2010 @ 5:00
pm.
PURPOSE AND RATIONALE
The purpose of this lab is to allow students to become comfortable with
signal handling and processing in Unix.
PRIMARY RESOURCES:
FAQ
(submission instructions and other useful stuff)
You should refer to the required reading sections of the assigned texts
in order to accomplish this lab.
If possible, you should ssh into the cluster to perform all lab
activities.
README
- If you are not in our course email list, please subscribe
to the cspp51081 email list here: http://mailman.cs.uchicago.edu/mailman/listinfo/cspp51081
;
- Before starting, please reviews lecture4 note carefully,
for each
part of lab, there is also specified reading assignment;
- Please pay attention to "DELIVERABLES" instruction in each
part;
- Turn the lab assignment in by email to the grader by the
due date.
LAB 4
-
Signal Handling
Write a signal handler that catches the CTRL-C (SIGINT signal 2) and
SIGUSR1 (signal 10) signals. Your process should not by
default exit on CTRL-C back to your shell. You may want to
look on the BLP
example on signals, or Chapter 6 of Molay's text if you're
using that.
The following requirements apply:
- You should accumulate the handling of CTRL-C in the
handler. That
is to say, you should have a variable counter accumulate each time the
handler
is called, and print out the current count in the handler.
For instance,
if you've hit CTRL-C 6 times, your handler should print out something
to
the effect of "You've pressed Ctrl-C 6 times. Aren't you
getting the
message that I'm invulnerable?"
- Your program should accept a command line argument that
specifies
the MAXSTOPS allowed, after which, Ctrl-C is handled in the default way
(i.e.,
the program terminates). So if the user passes in '10' on the
command
line, the program prints out it's message above the first 9 times, but
the
10th time CTRL-C is pressed, the default action applies (program
termination).
- You should print out a message that states that your
program received
the SIGUSR1 signal when it is handled. You should be able to
issue
a kill command to send your program the SIGUSR1 signal, and have that
signal
handled properly (by printing out a receipt notification) and then
continue
to function and handle subsequent CTRL-C and SIGUSR1 signals.
Please following these steps to finish this part
smoothly:
- Read "signal" session in Chapter 11 of BLP textbook or
in Chapter
6 of Molay's text.
- Read and understand the example code first.
- Understand that handling SIGUSR1 is one of the most
primitive forms
of interprocess communication in Unix (i.e., you are communicating with
another
process).
DELIVERABLES: your source file(s)
(e.g., my_sig.c), a makefile, and a README as
described in the
submission faq
MARKS DISTRIBUTION
- Excercise 1:
- 5.5 points: code that compiles, executes, and handles SIGINT as in point 4.1
- 5.5 points: correct accumulation of signal counts as in point 4.2
- 5.5 points: correct handling of MAXSTOPS argument as in point 4.3
- 5.5 points: correct handling of SIGUSR1 as in point 4.4
- 3 points: proper submission according to submission guidelines
Total Marks: 25
Atilla
Soner Balkir