Linux Signal Catcher
Catcher Due Date: September 26, 2014 @ midnight Submission Subject: “Catcher” ← this is the subject line of your email
General Submission Criteria: ● See Lab 0 for the General Submission Criteria! ● Make a directory in your repository: lab3 ● Include all of your Lab3 work within the lab3 directory
Overview: In this lab, you will develop single program that catches signals. When the program catches the signals, it writes particular information onto stdout.
Executable Names: catcher: a program that catches a number of predefined signals, and prints status information on stdout.
Makefile Targets: all: (default) catcher: clean:
Description: In this software project, you are to write a commandline tool that simply catches signals. The command line arguments define which signal to catch.
● The program processes the command line arguments ○ The arguments indicate which signals to catch
● The program emits a status line that includes its PID to stderr ● The program registers a handler for each argument (see signal(2)) ● The program pauses itself continually (see pause(2)) ● The handler registers itself again (read about unreliable signals) ● The handler emits a line to stdout that indicates
○ the signal caught, and ○ the time it was caught (see time(2))
● The program gracefully terminates after ○ receiving three successive SIGTERM signals (hint: static int count)
● The program emits a final status message to stderr that indicates ○ the number of signals caught
Usage Example:
$ catcher TERM USR1 USR2 catcher: $$ = 26843 SIGUSR1 caught at 1411497992 SIGTERM caught at 1411498002 SIGUSR2 caught at 1411498011 SIGTERM caught at 1411498076 SIGTERM caught at 1411499076 SIGTERM caught at 1411499976 catcher: Total signals count = 6 $
$ kill -USR1 26843 $ kill -TERM 26843 $ kill -USR2 26843 $ kill -TERM 26843 $ kill -TERM 26843 $ kill -TERM 26843
$ catcher TERM USR1 USR2 >/dev/null catcher: $$ = 26843 catcher: Total signals count = 6 $
$ kill -USR1 26843 $ kill -TERM 26843 $ kill -USR2 26843 $ kill -TERM 26843 $ kill -TERM 26843 $ kill -TERM 26843
See Also: ● man signal ● man 2 kill ● man kill ● man pause