\begin{exe} {Examining Signal Priorities and Execution}

   We give you a \textbf{C} program that includes a signal
   handler that can handle any signal. The handler avoids
   making any system calls (such as those that might occur
   while doing I/O).  This file can be extracted from your
   downloaded \verb?SOLUTIONS? file as \lablink{signals.c}

   \cfile[\texttt{signals.c}]{labs/signals.c}

   You will need to compile it and run
   it as in:
   \begin{cmd}
$ gcc -o signals signals.c
$ ./signals
   \end{cmd}

   When run, the program:
   \begin{itemize}
      \item
      Does not send the signals \verb?SIGKILL?  or
      \verb?SIGSTOP?, which can not be handled and will
      always terminate a program.
      \item
      Stores the sequence of signals as they come in, and
      updates a counter array for each signal that indicates
      how many times the signal has been handled.
      \item
      Begins by suspending processing of all signals and
      then installs a new set of signal handlers for all
      signals.
      \item
      Sends every possible signal to itself multiple times
      and then unblocks signal handling and the queued up
      signal handlers will be called.
      \item
      Prints out statistics including:

      \begin{itemize}
         \item

         The total number of times each signal was received.

         \item

         The order in which the signals were received, noting
         each time the total number of times that signal had
         been received up to that point.

      \end{itemize}
   \end{itemize}

   Note the following:

   \begin{itemize}
      \item

      If more than one of a given signal is \textbf{raised}
      while the process has blocked it, does the process
      \textbf{receive} it multiple times?  Does the
      behavior of \textbf{real time} signals differ from
      normal signals?

      \item

      Are all signals received by the process, or are some
      handled before they reach it?

      \item

      What order are the signals received in?

   \end{itemize}

   One signal, \verb?SIGCONT? (18 on \textbf{x86}) may not
   get through; can you figure out why?

   \begin{info}

      On some \textbf{Linux} distributions signals 32 and 33
      can not be blocked and will cause the program to
      fail. Even though system header files indicate
      \verb?SIGRTMIN=32?, the command \verb?kill -l?
      indicates \verb?SIGRTMIN=34?.

      Note that \textbf{POSIX} says one should use signal
      names, not numbers, which are allowed to be completely
      implementation dependent.

      You should generally avoid sending these signals.
   \end{info}

\end{exe}

