\section{Signals}

\begin{frame}
   {Signals}
   \begin{itemize}
      \item Signals are generally sent by one of two methods
      \begin{itemize}
         \item From the kernel to a user process as a
         result of an exception or programming error
         \item From a user process (via system call) to
         the kernel which will send it to a user
         process
      \end{itemize}
      \item Signals can only be sent between processes owned
      by the same user or from a process owned by the
      superuser to any process
   \end{itemize}

\end{frame}

\cprotect\note{

   Signals are used to inform processes of the occurrence of
   asynchronous events or exceptions.  An event is asynchronous
   in that the process receiving the signal may not be
   expecting the event to occur or may be expecting the event
   but cannot know exactly when it will occur.  For example, if
   a user decides to kill a program (process) that they had
   previously started, the interruption would be an
   asynchronous event causing a signal to be delivered to that
   process.

   There are a number of different types of signals and the
   signal sent by the kernel indicates what type of event (or
   exception) occurred.  Generally, signals are used to handle
   two things, 1) exceptions detected by hardware (such as an
   illegal memory reference), or 2) exceptions generated by the
   environment (such as the premature death of a process from
   the user's terminal).

   To see a list of the signals in \textbf{Linux}, along with their
   numbers use \texttt{kill -l} (that is the letter l not a
   one).  The meaning attached to the signal type indicates
   what event occurred causing the signal to be sent to a
   process (when sent from the kernel).  Also note that users
   can explicitly send any signal type to one of their
   processes, but the meaning attached is no longer implied by
   the signal number or type and can be used in any way that
   the process prefers to.  }



\begin{frame}
   {kill}

   \begin{itemize}
      \item Users invoke \textbf{kill} to send
      signals to other processes
      \item \textbf{kill} is a misnomer, should be
      send-signal
      \item \texttt{kill [pid]} sends the SIGTERM signal, by
      default
      \begin{itemize}
         \item If process does not handle (or catch) or
         ignore SIGTERM, then process is killed
      \end{itemize}
      \item \texttt{kill -signal [pid]} sends a specific
      signal to a process
   \end{itemize}

\end{frame}

\cprotect\note{

   Since a process cannot send a signal directly to another
   process, it must ask the kernel to send the signal.  Users
   (including the superuser) can send signals to other
   processes (programs) by using \textbf{kill}.

   \textbf{kill} is really a bad name.  Although it
   is used a lot to kill processes, it is really designed to
   send signals to processes.  Therefore, \textbf{kill} is not
   really accurate.

   The default signal sent is \texttt{SIGTERM} (\#15) which can
   be handled, or ignored by the receiving process in order to
   prevent its death.  It is preferable to use this signal to
   give the process a chance to clean up after itself. If this
   signal is ignored, the user can usually send a SIGKILL (\#9)
   signal, which cannot be ignored, to kill the process.

   We use \textbf{kill} to send signals (by either
   number or name):

   \begin{cmd}
$ kill 1234
$ kill -9 1234
$ kill -SIGTERM 1234
   \end{cmd}

   \begin{figure}[H]
      \includegraphics[height=1.8in]{IMAGES/sigkill}
      \caption{Available Signals}
   \end{figure}

}



\begin{frame}
   {killall}

   \begin{itemize}
      \item Uses process name instead of pid
      \item Sends signal to all processes with that name
      (assuming appropriate privileges)
   \end{itemize}

\end{frame}

\cprotect\note{

   \begin{cmd}
$ killall bash
$ killall -9 bash
$ killall -SIGKILL bash
   \end{cmd}
}


\begin{frame}
   {pkill}

   \begin{itemize}
      \item Sends signals to process using name
      \begin{cmd}
$ pkill [-signal] [options] [pattern]
      \end{cmd}
      \begin{itemize}
         \item \texttt{-P}: ppid
         \item \texttt{-G}: gid
         \item \texttt{-U}: uid
      \end{itemize}
   \end{itemize}

\end{frame}

\cprotect\note{

   Similar to \textbf{kill} but uses name instead of pid.

   Make \textbf{rsyslog} reread its configuration file:
   \begin{cmd}
$ pkill -HUP rsyslogd
   \end{cmd}
}


