\documentclass[english,serif,mathserif,xcolor=pdftex,dvipsnames,table]{beamer}
\usepackage[utf8]{inputenc}
%\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{fixltx2e}
\usepackage{graphicx}
\usepackage{colortbl}%
  %\newcommand{\cellcolor}[2]{\multicolumn{1}{>{\columncolor{#1}}c}{#2}}
\usepackage{listings}%
  \lstloadlanguages{sh}%
  \lstset{
    language=sh,%
    % --- basic appearance ---
    basicstyle=\ttfamily,%
    %columns=fullflexible,% best results for proportional fonts
    commentstyle=\small,%
    keywordstyle=\bfseries,% or \normalfont
    %identifierstyle=\itshape,%
    %procnamestyle=\bfseries\slshape, %\scshape,%
    %procnamekeys={def},%
    % --- escaping and special displays ---
    escapechar=@,% text between "@" will be rendered as normal TeX
    %moredelim=[il][\small\itshape]{\#},% ditto for text beween "#" and end-of-line
    texcl,%
    mathescape=false,%
    %literate={*{=}{{$\gets$ }}1 {==}{{$=$ }}1 {<=}{{$\leq$ }}1 {>=}{{$\geq$ }}1 {!=}{{$\neq$ }}1},%
    % --- display ---
    %showspaces=false,%
    %showstringspaces=false,%
    %xleftmargin=2em,%
    % --- line numbers ---
    %numbers=left,%
    %numberstyle=\tiny,%
    %stepnumber=1,%
    %firstnumber=1%
  }%
  \lstMakeShortInline{@}%
\usepackage{longtable}
\usepackage{multirow}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{soul}
\usepackage{textcomp}
\usepackage{tikz}%
  \usetikzlibrary{arrows,shapes}%
  % For every picture that defines or uses external nodes, you'll have to
  % apply the 'remember picture' style. To avoid some typing, we'll apply
  % the style to all pictures.
  \tikzstyle{every picture}+=[remember picture]%
\usepackage{marvosym}
\usepackage{wasysym}
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{url}
\tolerance=1000
\providecommand{\alert}[1]{\textbf{#1}}

\usetheme{uzhneu-en-informal}


\title[Introduction to the UNIX shell]{%
  Introduction to the UNIX \\
  command-line shell
}
\author[R. Murri]{%
  \textbf{Riccardo Murri} \\
  Grid Computing Competence Center, \\
  Organisch-Chemisches Institut, \\
  University of Zurich
}
\date{Sept.~27,~2011}

%% Use `\largeskip` to get a larger vertical white space between two
%% lines/paragraphs:
\newcommand{\largeskip}{\vspace{1em}}
\def\+{\largeskip}
\setlength{\parsep}{1.0em}

\begin{document}

% title frame
\maketitle


\begin{frame}
  \frametitle{Outline}
  
  Recap from yesterday's lecture:
  \begin{itemize}
  \item Local execution of programs (e.g., on your laptop)
  \item Batched execution of programs (e.g., on a cluster)
  \end{itemize}

  \+
  The goal of these initial lab sessions is to show what the
  difference is, in practice, and what tools are available in each
  case.

  \+
  We'll start with a short introduction to the UNIX command line
  shell. 

  \+
  {\small Slides available for download from: 
    \url{http://www.gc3.uzh.ch/teaching/lsci2011/lab01.pdf}}
\end{frame}


\section{Introduction}

\begin{frame}
  \frametitle{Layers of UNIX}
  \begin{columns}
    \begin{column}{0.5\textwidth}
      \begin{tikzpicture}
        \draw[fill,cyan!50]   (0,0) circle (7em); 
        \draw[fill,yellow!50] (0,0) circle (6em); 
        \draw[fill,red!50]    (0,0) circle (3em);
        
        \coordinate (topleft)  at (135:7.5em);
        \coordinate (topright) at (45:7.5em);
        \coordinate (bottom)   at (270:7.5em);

        \node [above=0.5ex] at (topleft) {\textbf{shell}};
        \node [above=0.5ex] at (topright) {\textbf{commands}};
        \node [below=0.5ex] at (bottom) {\textbf{kernel}};

        \draw[-, very thick] (topleft.south) -- (135:6.5em);
        \draw[-, very thick] (topright.south) -- (45:4.5em);
        \draw[-, very thick] (bottom.north) -- (270:1.5em);
      \end{tikzpicture}
    \end{column}
    \begin{column}{0.5\textwidth}
      A user interacts with the \emph{shell}:
      the purpose of a shell is to execute users' \emph{commands}.

      \+
      Command is just another word for a ``program''.
    \end{column}
  \end{columns}
\end{frame}


\begin{frame}
  \frametitle{Programs and processes}
  A \textbf{process} is an instance of a program that is being
  executed.

  \+ 
  Several processes may be associated with the same program: e.g.,
  the same collection of instructions can be performed on multiple
  data sets.\note{%
    Different users running the same program with the
    same data create distinct processes!
  }

  \+
  A \textbf{command} is the textual specification of a program and
  data to turn into a process.
\end{frame}


\begin{frame}
  \frametitle{Interaction with the shell}
  The shell:
  \begin{enumerate}
  \item reads commands from the user \emph{one line at a time},
  \item parses the command-line, and
  \item executes it.
  \end{enumerate}
\end{frame}

\begin{frame}
  \frametitle{Interaction with the shell: \emph{reading}}

  The shell reads commands \emph{one line at a time}.
  \note{%
    This originates in the usage of the UNIX shell using
    \href{http://en.wikipedia.org/wiki/Teletype}{teletypes}.  In modern
    graphical systems we use a \emph{terminal emulator} to provide this
    kind of character-based interaction.
    
    (There are advantages in keeping things this way, as we shall
    see.)
  }

  \+
  An interactive shell will print a \emph{prompt} to signal it's ready
  to accept input.
  \begin{center}
      \includegraphics[width=0.8\linewidth]{lab01/prompt}
  \end{center}
\end{frame}


\begin{frame}
  \frametitle{Interaction with the shell: \emph{parsing}}
  Any line input to the shell is split into \emph{words}, by scanning
  it character by caracter:
  \begin{itemize}
  \item Each occurrence of a quote character (\texttt{'},
    or \texttt{"}) accumulates all the text up to the next matching
    quote character into the current word.
    \begin{itemize}
    \item There are differences among the different quote characters,
      and some special treatment of other characters (e.g.,
      \texttt{\textbackslash}, \texttt{`}, \texttt{\#}, \ldots) but we
      shall see them aftwerwards.
    \end{itemize}
  \item Each occurrence of a (sequence of) blank characters ends the
    current word.
  \item A new word is started at the next (unquoted) non-blank character.
  \item A command-line is terminated at the first (unquoted)
    occurrence of newline, \texttt{;}, \texttt{|}, \texttt{\&}.
  \end{itemize}

  {\small\em Exact rules available at: 
    \url{http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html\#tag_02_03}}
\end{frame}


\begin{frame}
  \frametitle{Interaction with the shell: \emph{execution}}
  Each UNIX process is initialized with a list (1D array) of strings,
  called the \emph{argv} vector.

  \+
  Each word on the command-line is assigned to a string in the argv
  vector: the initial word (the command name) has index 0, and the
  index increases left-to-right.
\end{frame}


\begin{frame}[fragile]
  \frametitle{\emph{Hello, world} from the shell}
  
  At the shell prompt, type:
  \begin{center}
    \begin{minipage}{0.5\linewidth}
\begin{verbatim*}
echo Hello, world.
\end{verbatim*}
    \end{minipage}
  \end{center}

  \+
  What's the difference if we type this instead?
  \begin{center}
    \begin{minipage}{0.5\linewidth}
\begin{verbatim*}
echo "Hello, world."
\end{verbatim*}
    \end{minipage}
  \end{center}

  \+
  And with this?
  \begin{center}
    \begin{minipage}{0.5\linewidth}
\begin{verbatim*}
echo Hello, world;
\end{verbatim*}
    \end{minipage}
  \end{center}
\end{frame}


\begin{frame}[fragile]
  \frametitle{The most useful command of all}
  The command \texttt{man} displays the manual page of any other
  command on the system.

  \+
  Example:
  \begin{lstlisting}
    # shows the manual for the shell itself
    man sh
  \end{lstlisting}
\end{frame}


\begin{frame}
  \frametitle{A few other commands}

  \begin{tabular}{rl}
    \texttt{ls}    & List the contents of a directory \\
    \hline
    \texttt{cat}   & Show the contents of a file \\
    \texttt{zcat}  & Show the contents of a \emph{compressed} file \\
    \texttt{more}  & Show file contents, one screenful at a time \\
    \texttt{less}  & A \texttt{more} with more advanced functionality \\
    \hline
    \texttt{gzip}  & Compress a file \\
    \texttt{gunzip}& Uncompress a file \\ 
    \hline
    \texttt{wget}  & Download a URL to a file \\
    \hline
    \parbox{0.25\linewidth}{\raggedleft
      \texttt{gedit}, \texttt{emacs}, \texttt{vi}, \texttt{nano}} 
    & Text editors
   \end{tabular}
  
\end{frame}


\begin{frame}
  \frametitle{Shell scripts}
  A shell read its input line by line, but \emph{not necessarily from
    a terminal!}.

  \+
  You can tell the shell to read and execute commands from a file, by
  passing it as the first argument to the shell.

  \+ 
  A file containing shell commands is called a \emph{shell script}.

  \+
  \textbf{Exercise:} Write a shell script that displays the single
  line ``Hello, world.''
\end{frame}


\begin{frame}[fragile]
  \frametitle{Shell variables}
  Shell variables are automatically created when they are first
  assigned a value:\footnote{%
    \emph{Note:} no spaces allowed around the
  equal sign ``\texttt{=}''.}
  \begin{center}
\begin{lstlisting}
ANSWER=42
name=John
\end{lstlisting}
  \end{center}

  \+
  The value of a variable is taken by prefixing its name with the
  character \texttt{\$}; i.e., the string \texttt{\$name} is
  substituted with the value of the variable \texttt{name}, as if it
  had been typed directly on the command-line.
\end{frame}


\begin{frame}[fragile]
  \frametitle{Variable expansion}
  Substituting the value of a variable in a command line is called
  \emph{variable expansion}.

  \+
  Examples:
  \begin{center}
\begin{lstlisting}
# What do you think this will display?
name=John; echo Hello, $name;

# and this one?
name="John Doe"; echo Hello, $name;
\end{lstlisting}
  \end{center}

  You can use \lstinline"${name}" instead of \lstinline"$name".

  {\small\em (When could this be useful?)}

  \+ 
  \emph{Note:} Variable expansion occurs \emph{inside} double quotes
  (\texttt{"}) as well, but not inside single quotes (\texttt{'})
\end{frame}


\begin{frame}[fragile]
  \frametitle{Special Variables: Positional arguments}
  The special variables \lstinline"$0", \lstinline"$1",
  \lstinline"$2", etc. expand to the corresponding string in the
  \emph{argv} vector.%$

  \+
  {\small\em (How do you get the 11-th command-line argument?)}

  \+
  \textbf{Exercise:} Write a \texttt{hello.sh} script, that takes one
  argument on the command-line (a person's name), and outputs a single
  line, consisting of the words ``Hello,'' followed by the name.

  \+
  Example:
  \begin{lstlisting}
    $ sh hello.sh Joe
    Hello, Joe.
  \end{lstlisting}%$
\end{frame}


\begin{frame}
  \frametitle{UNIX process I/O}
  UNIX processes perform Input/Output operations on
  \href{http://en.wikipedia.org/wiki/Standard_streams}{\textbf{streams}}.

  \+
  Three streams are available to any process:
  \begin{itemize}
  \item \textbf{standard input} (stdin): data which is \emph{read} by
    the program.
  \item \textbf{standard output} (stdout): the stream where a process
    \emph{writes} its main output data.
  \item \textbf{standard error} (stderr): an additional stream for
    writing error messages, diagnostics or progress messages.
  \end{itemize}
  More streams can be opened by a program while it's running.

  \+
  {\tiny\em (Can you think of an example to motivate the stdout/stderr
  separation?)}
\end{frame}


\begin{frame}
  \frametitle{I/O redirection}
  A process' \emph{stdin}, \emph{stdout} and \emph{stderr} are
  normally connected to whatever streams its parent shell was
  connected to.

  \+
  There is special shell syntax for specifying where the streams of a
  command should be \emph{redirected} to.

  \+
  \begin{tabular}{lp{0.66\linewidth}}
    \texttt{\textit{command} > file} 
    & stdout of \texttt{\textit{command}} is written to \texttt{\textit{file}} \\
    \texttt{\textit{command} >> file} 
    & stdout of \texttt{\textit{command}} is appended to \texttt{\textit{file}} \\
    \texttt{\textit{command} >\& file} 
    & stdout \emph{and} stderr of \texttt{\textit{command}}
      are written to \texttt{\textit{file}} \\
    \hline
    \texttt{\textit{command} < file} 
    & stdin of \texttt{\textit{command}} is read from \texttt{\textit{file}} \\
    \hline
    \texttt{\textit{c1} | \textit{c2}} 
    & stdout of \texttt{\textit{c1}} is stdin of \texttt{\textit{c2}}
  \end{tabular}
\end{frame}


\begin{frame}
  \frametitle{Exercises on I/O redirection}
  Write a script that, given a file name and a person name on the
  command-line, will write the usual ``Hello'' greeting to the
  specified file.

  \+
  Write a script that, given a matrix file name (e.g., \texttt{M0,6-D5}):
  \begin{enumerate}
  \item Downloads the compressed matrix file from
    \url{http://www.gc3.uzh.ch/gc3wiki/teaching/grid2011/lab2/}
    (compressed files have a \texttt{.gz} extensions)
  \item Uncompresses the matrix file (e.g., \texttt{M0,6-D5.sms.gz})
    into a plain-text file (e.g., \texttt{M0,6-D5.sms})
  \end{enumerate}
\end{frame}


\begin{frame}
  \frametitle{The UNIX filesystem, 1}
  \begin{columns}
  \begin{column}{0.4\textwidth}
    \includegraphics[width=\linewidth]{lab01/tree}
  \end{column}
  \begin{column}{0.6\textwidth}
  UNIX' directories are organized in a \emph{single} tree-like
  structure.  Files are the leaves of this tree.

  \+ 
  There's is one and only one root directory, denoted by
  `\texttt{\textbackslash}'.

  \+
  The directory tree is not confined into a single disk; every accessible
  disk/partition/network storage corresponds to a subtree.
  The branch where this subtree is rooted is called a \emph{mount point}.
  
  % \+
  % \begin{tabular}{rl}
  %   \texttt{df} & shows mount points and the free space on each of them.
  % \end{tabular}
  \end{column}
  \end{columns}
\end{frame}


\begin{frame}[fragile]
  \frametitle{The UNIX filesystem, 2}
  Files are the leaves of the directory tree.
  
  \+
  Each file can be identified by specifying the path along the tree to
  reach that leaf from the current node.
  Nodes encountered along the path (so-called \emph{path compoments})
  are separated by `\texttt{\textbackslash}'.
  
  \+
  \begin{description}
    \item[\url{/home/murri/lsci/lab1.tex}]
      {\raggedright absolute path (= starting from the root)}
    \item[\url{lsci/lab1.tex}]
      {\raggedright relative path (= starting from the current node)}
    \item[\url{..}]
      {\raggedright relative path to upper-level directory}
  \end{description}
\end{frame}


\begin{frame}
  \frametitle{Filesystem commands}
  \begin{tabular}{rl}
    \texttt{pwd}   & path to current directory
    \\[-2pt]
    \texttt{cd}    & change current directory
    \\[-2pt]
    \texttt{mkdir} & make a new directory
    \\[-2pt]
    \texttt{rmdir} & remove/delete an existing directory
    \\[-2pt]
    \texttt{ls} & list contents of a directory
    \\ 
    \hline
    \texttt{cp} & copy files
    \\
    \texttt{mv} & move/rename files
    \\
    \texttt{rm} & remove/delete files
  \end{tabular}
\end{frame}

\begin{frame}
  \frametitle{Options, 1}
  Options select an alternate behavior of a command.
  
  \+ 
  By \emph{convention}, options start with the `\texttt{-}' character.

  \+ 
  Examples:
  \begin{tabular}{rl}
    \texttt{ls -s *.tex} & one option, one argument
    \\
    \texttt{ls -sh} & two options, combined
    \\
    \texttt{ls -s -h} & two options, separately written
    \\
    \texttt{ls --size} & long form of the `\texttt{-s}' option
    \\
    \texttt{ls --help} & quick help on command usage
  \end{tabular}
\end{frame}


\begin{frame}
  \frametitle{Options, 2}
  Some options require an argument as well.
  \begin{tabular}{l}
    \texttt{tar --create --file=tex.tar *.tex}
    \\
    \texttt{tar --create --file tex.tar *.tex}
    \\
    \texttt{tar --create -f tex.tar *.tex}
    \\
    \texttt{tar -c -ftex.tar *.tex}
  \end{tabular}
\end{frame}


\begin{frame}
  \frametitle{The exit code}
  Upon termination, each UNIX process specifies an \emph{exit code},
  which is an 8-bit unsigned integer.

  \+
  By \emph{convention}, exit code 0 means OK/success/true.

  \+ 
  Any exit code different from 0 is \emph{normally} interpreted as
  error/failure/false.

  \+
  \emph{Note:} This is the \emph{opposite} convention than used, e.g.,
  in C.

  \+ The exit code of the \emph{last} executed command is available as
  the special shell variable \lstinline"$?"%$
\end{frame}


\begin{frame}[fragile]
  \frametitle{Conditionals, 1}
  The shell supports conditional execution of commands:
  \begin{lstlisting}
    if @\itshape command@; then
      # do this when exitcode 0...
    else
      # otherwise do this...
    fi
  \end{lstlisting}

  \+ 
  The \lstinline"if" statement only checks the exit code of
  {\ttfamily\itshape command}.
  
\end{frame}


\begin{frame}[fragile]
  \frametitle{Conditionals, 2}
  Any command can be used for the test clause in a conditional.

  \+ 
  However, the \texttt{test} command is the more frequently used:
  \begin{tabular}{rp{0.66\linewidth}}
    \texttt{test -r {\itshape path}}
    & {\raggedright True if {\ttfamily\itshape path} is readable.}
    \\
    \texttt{test -w {\itshape path}}
    & {\raggedright True if {\ttfamily\itshape path} is writeable.}
    \\
    \texttt{test -d {\itshape path}}
    & {\raggedright True if {\ttfamily\itshape path} is a directory.}
    \\
    \texttt{test -z "{\itshape string}"}
    & {\raggedright True if {\ttfamily\itshape string} is null.}
    \\
    \texttt{test -n "{\itshape string}"}
    & {\raggedright True if {\ttfamily\itshape string} is \emph{not} null.}
    \\
    \texttt{test "{\itshape s1}" = "{\itshape s2}"}
    & {\raggedright True if the strings are equal.}
    \\
    \texttt{test "{\itshape s1}" != "{\itshape s2}"}
    & {\raggedright True if the strings are different.}
  \end{tabular}
  \ldots and many more: `\texttt{man test}' is your friend!

  \+
  The open bracket \texttt{[} is an alias for \texttt{test}, but it
  requires a closing \texttt{]} at the end; e.g.,
  \begin{lstlisting}
    [ -d /tmp ] || # do something...
  \end{lstlisting}
\end{frame}


\begin{frame}
  \frametitle{Conditionals, 3}

  \textbf{Exercise:} Modify the \texttt{hello.sh} script: if the name
  given on the command-line is ``Mary'', then it should print ``Happy
  birthday, Mary.''; if any other name is given, print ``Hello, \ldots''

\end{frame}


\begin{frame}
  \frametitle{Conditionals, 4}
  Other syntaxes for conditional execution of commands:
  \begin{tabular}{rp{0.66\linewidth}}
    \\[1ex]
    \texttt{{\itshape cmd1} \&\& {\itshape cmd2}}
    & {\raggedright Execute {\ttfamily\itshape cmd2} if and only if
      {\ttfamily\itshape cmd1} exited with code 0.}
    \\[2ex]
    \texttt{{\itshape cmd1} || {\itshape cmd2}}
    & {\raggedright Execute {\ttfamily\itshape cmd2} if and only if
      {\ttfamily\itshape cmd1} exited with code \emph{non-zero}.}
  \end{tabular}

  \+
  The \texttt{\&\&} and \texttt{||} operators are left-associative.
\end{frame}


\begin{frame}[fragile]
  \frametitle{``while''-loops}
  \begin{lstlisting}
    while @\itshape command@; do
      # do this while exit code is 0
    done
  \end{lstlisting}

  \+ 
  The specified {\ttfamily\itshape command} is executed at each
  iteration: if its exit code is 0, then the body of the loop is
  executed; otherwise the shell continues with the next instructions
  after the \lstinline"done" statement.
\end{frame}


\begin{frame}[fragile]
  \frametitle{``for''-loops, 1}
  \begin{lstlisting}
    for @\itshape variable@ in @\itshape value1@ @\itshape value2@ @...@; do
      # do this for every value of \$variable
    done
  \end{lstlisting}%$

  \+
  The body of the loop is executed once for each value to be assigned
  to {\ttfamily\itshape variable}.

  \+ 
  \emph{Note 1:} The list of values is terminated by `\texttt{;}'.

  \+ 
  \emph{Note 2:} Each {\ttfamily\itshape value} is a \emph{word} in
  shell syntax.  In particular, the list of values is space-separated.
\end{frame}


\begin{frame}[fragile]
  \frametitle{``for''-loops, 2}

  The special shell variable \texttt{\$@} expands to the \emph{list}
  of arguments passed on the command-line.

  \+
  \textbf{Exercise:} Write a \texttt{multihello.sh} script that takes
  a variable number of names on the command-line and, for each of
  these names prints ``Hello, \emph{name}'' on a separate line.
\end{frame}


\begin{frame}[fragile]
  \frametitle{Background execution}
  The `\texttt{\&}' operator may be specified at the end of a
  command-line to indicate that the command should be executed in the
  background, i.e., concurrently with the shell and with no
  interaction with the terminal.

  \+
  Example:
  \begin{lstlisting}
    # decompress a file in the background
    gunzip M0,6-D6.sms.gz &
  \end{lstlisting}

  \+
  A backgrounded process cannot read from stdin nor write to stdout.
  (It will be stopped by the kernel if it tries to.)
\end{frame}


\begin{frame}[fragile]
  \frametitle{Controlling UNIX processes, 1}
  Each process is assigned a unique numeric \emph{process identifier}
  (PID).

  \+ 
  The shell variable \texttt{\$!} contains the PID of the most
  recently-started background command.

  \+ 
  The \texttt{ps} and \texttt{kill} commands can be used to control a
  process given its PID:
  \begin{tabular}{rp{0.50\linewidth}}
    \\[1ex]
    \texttt{ps [{\itshape PID}]}
    & {\raggedright Print information on a process.}
    \\[2ex]
    \texttt{kill [{-l \itshape SIGNAL}] {\itshape PID}}
    & {\raggedright Send a signal to a process. (By default, SIGTERM)}
  \end{tabular}
\end{frame}


\begin{frame}[fragile]
  \frametitle{\texttt{ps} usage}
  Example of \texttt{ps} usage:
  \begin{lstlisting}
$ ps 1051
 PID TTY      STAT   TIME COMMAND
1051 pts/3    T      0:01 emacs -nw src.c++/examples/rank.cpp
  \end{lstlisting}%$
  The naming of parts:
  \begin{tabular}{rl}
    \texttt{PID}  & {The process ID.} 
    \\
    \texttt{TTY}  & {The controlling terminal.}
    \\
    \texttt{STAT} & {Kernel process status.}
    \\
    \texttt{TIME} & {CPU time consumed so far.}
    \\
    \texttt{COMMAND} & {Command-line that started this process.}
  \end{tabular}

  \+ 
  The \texttt{ps} output can be customized to print almost every field
  of the kernel process table. (Use `\texttt{man ps}'.)
\end{frame}


\begin{frame}
  \frametitle{Process statuses}
  \begin{tabular}{rp{0.75\linewidth}}
    \texttt{D} & {\raggedright Uninterruptible sleep (usually I/O).}
    \\
    \texttt{R} & {\raggedright Running or runnable (on run queue).}
    \\
    \texttt{S} & {\raggedright Interruptible sleep (waiting for an event to complete).}
    \\
    \texttt{T} & {\raggedright Stopped, either by a job control signal or because it is being traced.}
    \\
    \texttt{Z} & {\raggedright Defunct ("zombie") process, terminated but not reaped by its parent.}
  \end{tabular}

  \+
  {\small More info:
    \url{http://www.informit.com/articles/article.aspx?p=370047}}
\end{frame}


\begin{frame}[fragile]
  \frametitle{Controlling UNIX processes, 2}
  Using the \texttt{kill} command a process can be sent a signal,
  e.g., to terminate it, or temporarily suspend execution.

  \+
  \begin{tabular}{rp{0.75\linewidth}}
    \texttt{SIGTERM}
    & {\raggedright Ask process to terminate. (The process may choose
      to ignore this signal.)}
    \\
    \texttt{SIGKILL}
    & {\raggedright Terminate process forcibly, here and now.}
    \\
    \texttt{SIGHUP}
    & {\raggedright Sent to a process when the controlling terminal
      has been disconnected (e.g., \texttt{ssh} session closed).}
  \end{tabular}

  \+
  Example:
  \begin{lstlisting}
    # forcibly terminate a process
    kill -l KILL @\itshape PID@;
  \end{lstlisting}
\end{frame}


\begin{frame}
  \frametitle{References}
  \begin{enumerate}[{[1]}]
  \item A stream is ``an ordered sequence of data bytes which can be
    read until the end of file''; from:
    \url{http://en.wikipedia.org/wiki/Standard_streams}
  \item U.~Waldmann, ``A Guide to Unix Shell Quoting'',
    \url{http://www.mpi-inf.mpg.de/~uwe/lehre/unixffb/quoting-guide.html}
    (A readable introduction and reference on shell quoting.)
  \item
    The POSIX Shell Command Language Specification,
    \url{http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html}
  \end{enumerate}
\end{frame}


\begin{frame}
  \frametitle{Further reading}
  \begin{itemize}
  \item
    \href{http://tldp.org/LDP/Bash-Beginners-Guide/html/Bash-Beginners-Guide.html}{``Bash
    Guide for Beginners''} by M.~Garrels, \url{http://tldp.org/LDP/Bash-Beginners-Guide/html/Bash-Beginners-Guide.html}
\item \href{http://www.freeos.com/guides/lsst/}{``Linux Shell Scripting
    Tutorial - A Beginner's handbook''} by V.~G.~Gite, \url{http://www.freeos.com/guides/lsst/}
\item \href{http://tldp.org/LDP/abs/html/}{``Advanced Bash-Scripting
    Guide} by M.~Cooper, \url{http://tldp.org/LDP/abs/html/}
  \end{itemize}
\end{frame}
\end{document}
