Lab 3: Processes and Signal Handlers

This lab (and Lab 4) will give you practice working with processes, which is the basis of Project 1.

For reference, you should consult sections 2.5 and 2.7 of the book. You should also consult the POSIX documentation as needed for the following functions:

  • exit(), fork(), wait(), write()
  • kill(), sigaction(), sigemptyset()

Preliminaries

Set up a bare repository on stu.cs.jmu.edu based on the instructions in the CS 361 Submission Procedures, using the name lab3-proc.git.


Implementation Requirements: Processes and Signals

Your first task is to complete the implementation of run_child() in child.c. This function should create a child that runs and exits. The parent should get the child's exit status and print the message. Note that the fprintf() line is written to STDERR and does not affect the test cases; it is just for your reference when running the code.

Next, you will complete the functionality in signals.c, which focuses on signal handling. The first step is to complete signal_lookup(), which will return the number for a given signal name. For example, signal_lookup("INT") would return 2. You will need to look up the other values in /usr/include/asm/signal.h.

Once you have completed that function, complete the rest of the code in this file. Both catch_loop() and catch_segfault() will create a child process that overrides a signal handler and does something bad. In the former case, the child enters an infinite loop; the parent will wait for 60 seconds, then terminate the child with the SIGINT signal. In the latter case, the child causes a segmentation fault. In both cases, you must use a signal handler to print the message as explained in the comments.



James Madison University logo


© 2011-2024 Michael S. Kirkpatrick.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.