Lab 7: Signals
You are given a basic signal handling program to start with. Your job in this lab is to extend it to:
- Reset the counter to 0 every 15 seconds using SIGALRM. Make sure this works every 15 seconds, not just once.
- Add 5 to the counter when the user presses Ctrl+\ (SIGQUIT)
- Add 10 to the counter when SIGUSR1 is received
- Exit gracefully (print the final count and “Goodbye!") when SIGINT is received
- (already provided)
Sending Signals
You can send a signal to a process with the kill
command:
kill -s SIGQUIT <pid>
The example program prints its PID when starting up, so you can open another terminal and then use the kill
command to send the signals.
In the Shell
Think about how the basic shell we built in class might use signals. If you’ve implemented most of the functionality we’ve covered, try executing a long-running program and sending SIGINT with Ctrl+C to observe what happens.
Grading and Submission
Once you are finished with the lab, check your code into a directory called lab7
in your lab repository.
To receive full credit for this lab:
- Implement the 15-second counter reset, SIGQUIT, and SIGUSR1 handling.
- Answer the question above about how signals might relate to the basic shell we built in class.