HW 9: Signals
Instructions
- You must turn in a sheet of paper that is neatly typed or written answering the questions below. (You are strongly encouraged to type your homework.)
- This homework is graded out of 100 points. Point values are associated to each question.
Questions
- (5 points) What does it mean that signals arrive asynchronously?
- (10 points) What signal is generated from the following keyboard-shortcut/command?
- Ctrl-c
- Ctrl-z
- fg/bg
- Ctrl-\
- (15 points) Run the command
kill -l
to list all the signals and their signal numbers. Find either the matching signal-number/signal-name for the following values below. Additionally, for each signal, useman 7 signal
to describe the default action of each.SIGKILL
- 14
SIGALRM
SIGABRT
- 21
- 1
SIGCHLD
SIGTTOU
- (15 points) Provide a brief plain-English explanation, e.g., reference which
signal is sent and to which process(es), for each the
kill/killall commands. (hint: You should look in the man
pages…)
- killall -17 sleep
- kill -9 2237
- killall -SIGUSR1 a.out
- kill -SIGABRT -1
- killall sleep
- killall -u
On a lab machine, run the following program in the background
~aviv/ic221-hw/hw09/ic221-signaler &
From the same (or another) terminal on the same machine, send the program the following two signals below and describe the results.
- (3 points)
SIGUSR1
- (3 points)
SIGUSR2
- (3 points)
Consider the program below and answer the associated questions:
int count = 0; void handler(int signum){ printf("You Shot Me!\n"); count++; if(count > 3){ printf("I'm dead!\n"); exit(1); } } int main(){ //establish signal hander for SIGTINT and SIGSTOP signal(SIGTINT,handler); signal(SIGTSTP,handler); //loop forever while(1); }
- (3 points) What is the output of the program if the user hits Ctrl-c only once? Explain.
- (3 points) What is the output of the program if the user hits Ctrl-c four times? Explain.
- (3 points) What is the output of the program if the user hits Ctrl-c three times and Ctrl-Z once? Explain.
- (5 points) What does the system call
pause()
do? Yes, it pauses the program, of course, but until when does the program stay paused and why is it a useful command? (10 points) How many times doe the program below print
alarm
? Explainint count = 10; void handler(int sugnum){ printf("Alarm!\n"); count /= 2; alarm(count); } int main(){ signal(SIGALRM, handler); alarm(count); while(1) pause(); }
(10 points) Convert the following use of
signal()
below to asigaction()
call.signal(SIGUSR1, handler);
- (5 points) What
sigaction
flag is used to ensure that system calls will be restarted when interrupted? - (5 point) Provide an example of why the
read()
system call would need to be restarted due to a signal delivery. - (5 points) Look in
man 7 signal
andkill -l
and draw a picture of your favorite signal. Be sure to clearly identify it. (You will not use LaTex bonus points for hand drawing your picture.)