Assignment 3: Signals
Due by: Monday, February 17, 2025 at 11:59 p.m.
In this assignment, you'll get experience forking processes and creating custom signal handlers.
As with all the assignments and projects in this course, it's recommended that you do the stages in the order given. Get the MIN unit tests passing before moving on to the FULL ones. Likewise, get the MIN integration tests passing before moving on to the FULL one.
First, download the archive given below and unzip it into an appropriate directory.
Stage 1: Signal Handling
Complete enough of the implementation to detect and override the SIGSEGV signal:
- Complete the implementations of sig2msg() and getsig() functions in signals.c. These two functions will translate between signal names and numbers. For example, getsig() will translate the string "SEGV" into the number 11 (because SIGSEGV is signal 11). Likewise, sig2msg() will convert 11 into the message "SEGFAULT".
- Complete the sig_handler() in child.c to print out the message "SEGFAULT" for signal 11.
- Complete the implementation of run_child() in child.c to create a child process (by calling fork()) and override the default SIGSEGV handler in that child process. After the child process sets up the signal handler, call sem_post (start), and then trigger a segmentation fault. For example, you could declare an invalid pointer and dereference it. The parent should simply return to main().
- Implement the if-block of code in main.c that is identified as the MINIMUM CRITERIA. After calling run_child(), this code should use wait() to make sure the child completes.
Additional Signals
Extend the previous implementation to override the default handlers for all of the following signals:
- SIGSEGV
- SIGHUP
- SIGINT
- SIGFPE
- SIGALRM
Modify the main() implementation from above to take one of these signals from the command line and send the signal to the child. At this point, you should remove the code that causes the segmentation fault from the child process. Also, all of these signal handlers should be overridden: The ones passed on the command line with the -s flag should use sig_handler() while the others should use sig_unknown().
Stage 2: Signal Resetting
Complete the implementation of the functions in signals.c based on the comments there. Note that you will need special functions: siglongjmp(), sigsetjmp(), and sigprocmask(). The comments link to pages in the C standard library documentation for you to consult. Recall that the siglongjmp() and sigsetjmp() pair allow execution to jump from one function to the middle of another one without using the standard calling mechanism. Add code to main() to trigger SIGTSTP twice, but wait for 1 second between the two signals.
Turn In
First, run make clean to remove all of the executable and object files from your directory structure. Then, zip up the contents of your project directory in either a .zip or a .tar.xz file. Upload this archive to Brightspace. Your assignment must be submitted by Monday, February 17, 2025 at 11:59 p.m. Grace days are not available for assignments.
All work must be done within assigned teams, though you may discuss general concepts with your classmates. Please refer to the course policies if you have any questions about academic integrity. If you have trouble with the assignment, I am always available for assistance.
Under no circumstances should any member of one team look at the code written by another team. Tools will be used to detect code similarity automatically.
Code that does not compile will automatically score zero points.
Grading
Your grade will be determined by the following categories.
Category | Description | Weight |
---|---|---|
Unit Tests | Your solution passes the four unit tests. | 36% |
Integration Tests | Your solution passes the eight integration tests. | 64% |
Credits
This assignment is based on material from CS 361 by Michael S. Kirkpatrick. This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.