Lab 2: POSIX Signals

In this lab, we will learn about using POSIX (Unix) signals. The POSIX standard for signals, as with most of its components was based on UNIX semantics, but generalized to avoid explicitly endorsing one version of UNIX or another. The POSIX standard for signals and other aspects of system support are often supported by other operating systems. As with the other labs in this class we will experiment with signals in the context of Linux. We will also construct a small program which associates signal handlers with a few signals to give more interesting functionality to the starter code provided.

In this lab we will ensure you see how signals are used by BASH to support job control, which is an interesting feature, if slightly less widely used than it was a number of years ago. We will also look at a simple user program and change it in ways demonstrating:

 

Lab Materials
  1. Slides
  2. Lab Files
Assignment

For this lab, you need to complete the implementation of the signals.c program. This program should count the number of times the user has sent the SIGINT signal to the running process. Pressing Ctl-C from the keyboard send this signal. When the process receives the SIGTSTP signal (Ctl-Z), it should print to the terminal the number of SIGINT signals it has received. After it receives 5 SIGINT signals, the program should prompt the user to exit. If the user does not respond within 3 seconds, an SIGALRM signal should force the program to exit.

An example output of running signals is shown below:

	bash> ./signals 
	^C^C^C^C^C
	Really exit? [Y/n]: n

	Continuing
	^C^C^C^Z

	So far, '3' Ctl-C presses were counted

	^C^Z

	So far, '4' Ctl-C presses were counted

	^C
	Really exit? [Y/n]: n

	Continuing
	^C^C^C^C^C
	Really exit? [Y/n]: 
	User taking too long to respond. Exiting  . . .

 

When you're finished
Code submission will be through Canvas. You also need to tar up your lab for submission. For this step, you should use the 'zip' target included in the lab's Makefile. Change the STUDENT_ID variable in the Makefile to your student ID and type:
    make zip

 

Evaluation

 

The total marks for this lab will be awarded based on the submission of your code and your quiz answers.
  1. STEP 1 (Defining alarm handler) (15 points)
  2. STEP 2 (Clearing sa memory) (10 points)
  3. STEP 3 (Setting up mask set) (10 points)
  4. STEP 4 (Unblocking SIGALRM) (10 points)
  5. STEP 5 (Setting up SIGINT, SIGTSTP, and SIGALRM signal handlers) (20 points)
  6. STEP 6 (Ensuring program keeps running) (10 points)

  7. 10% (Quiz) - A short quiz about signals will be open on the following week during the lab hours
  8. 15% (Demo) - A quick demo of your submission will be taken on the following week during the lab hours

< Back to the Lab Home Page