IC221: Systems Programming (SP18)


Home Policy Calendar Units Assignments Resources

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

  1. (5 points) What does it mean that signals arrive asynchronously?
  2. (10 points) What signal is generated from the following keyboard-shortcut/command?
    1. Ctrl-c
    2. Ctrl-z
    3. fg/bg
    4. Ctrl-\
  3. (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, use man 7 signal to describe the default action of each.
    1. SIGKILL
    2. 14
    3. SIGALRM
    4. SIGABRT
    5. 21
    6. 1
    7. SIGCHLD
    8. SIGTTOU
  4. (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…)
    1. killall -17 sleep
    2. kill -9 2237
    3. killall -SIGUSR1 a.out
    4. kill -SIGABRT -1
    5. killall sleep
    6. killall -u
  5. 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.

    1. (3 points) SIGUSR1
    2. (3 points) SIGUSR2
  6. 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);
    
    }
    
    1. (3 points) What is the output of the program if the user hits Ctrl-c only once? Explain.
    2. (3 points) What is the output of the program if the user hits Ctrl-c four times? Explain.
    3. (3 points) What is the output of the program if the user hits Ctrl-c three times and Ctrl-Z once? Explain.
  7. (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?
  8. (10 points) How many times doe the program below print alarm? Explain

    int count = 10;
    
    void handler(int sugnum){
    
      printf("Alarm!\n");
      count /= 2;
      alarm(count);
    
    }
    
    int main(){
    
      signal(SIGALRM, handler);
      alarm(count);
    
      while(1) pause();
    }
    
  9. (10 points) Convert the following use of signal() below to a sigaction() call.

    signal(SIGUSR1, handler);
    
  10. (5 points) What sigaction flag is used to ensure that system calls will be restarted when interrupted?
  11. (5 point) Provide an example of why the read() system call would need to be restarted due to a signal delivery.
  12. (5 points) Look in man 7 signal and kill -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.)