\subsection{How can I log out?
Let me count the ways\ldots.}
\subsubsection{What does ``being logged in'' mean?}

When you type your username and password to the Unix ``login:'' and
``Password:'' prompts, you are ``logged in'' to the system. But what does
``logged in'' really mean?
\begin{sloppypar}
The Unix system maintains a list of every user currently logged in to a
computer in the file {\it /etc/utmp}. Among other information, this file
contains the username, terminal, and login time of every user currently
logged in. Most of the commands that report who is logged into the
computer, such as {\tt finger} and {\tt who}, look at this file to
figure out who is logged in.

When you login, a program called {\tt login}\footnote{{\tt login} is the
same program that asks for your password with the ``Password:'' prompt.
The ``login:'' prompt actually comes from a program called {\tt getty}.}
creates an entry in the {\it /etc/utmp} file with your username and
other information. {\tt login} then starts up a shell {\tt csh} running
on your terminal.
\end{sloppypar}

Another program, called {\tt init}, monitors your shell and waits for it
to die. When the shell dies, {\tt init} removes your entry from {\it
/etc/utmp}.

So logging out means doing one of two things: either killing your shell
or removing your entry from {\it /etc/utmp}.  Since only root (the
superuser) can modify {\it /etc/utmp}, we will concentrate on the
various methods of killing a shell.

\subsubsection{Standard logout}
There are many ways to kill the shell. The usual way is to type:
\begin{verbatim}
% logout
\end{verbatim}
This causes the shell to clean up its files, save your history in the
{\it .history} file, and execute your {\it .logout} file.

If you are typing to a shell in an {\tt xterm}, it may respond ``Not
login shell\.'' and return you to a prompt.  In this case, typing {\tt
exit} repeatedly will eventually destroy that window (and log you out if
it is your login window).

Typing {\tt exit} to a shell has the same effect as {\tt logout} (if it is a
login shell) and will clean up other non-login shells.

\subsubsection{Hanging up}
Another way you can logout is by hanging up the telephone (if you have
called in on a dial-up). This method is not guaranteed to work---it
depends on the computer's modem figuring out that you have hung-up
and sending a SIGHUP (signal-hangup) to your shell.

\pagebreak
But if you are not logged in via a modem, you can still send a SIGHUP to
your shell with the KILL command:
\begin{verbatim}
% kill -HUP $$
\end{verbatim}
The -HUP specifies that you want to send the SIGHUP signal.  The shell
replaces ``\$\$'' with its own process id. This means that if your shell is
process number 1322 and you type
\begin{verbatim}
% kill -HUP $$
\end{verbatim}
it becomes
\begin{verbatim}
% kill -HUP 1322
\end{verbatim}
which sends SIGHUP to your shell, killing it gracefully (but your shell
will {\em not} execute your .logout file if it is killed with a SIGHUP).

\subsubsection{Killing all your processes}

Another {\tt kill} command you can use to logout is
\begin{verbatim}
% kill -9 -1
\end{verbatim}
However, this command will {\em not} log you out if you issue it from
your login shell.

Under Unix\super{TM}, attempting to kill job number ``-1'' results in
a kill signal sent to all processes owned by the user {\em except for
the process from which the signal is issued.}  In other words, all
processes other then the shell from which you type the kill command
will die.

If you want to logout, issue this command from a shell other than your
login shell.

\subsubsection{Using {\tt exec}}

Normally, when you type commands to the shell, the shell creates a new
subprocess to execute the command.  The shell then waits for the process
to exit before prompting you for the next command.

The {\tt exec} command allows you to have the shell's process execute
the command itself; the shell goes away and is replaced by the program
named in the {\tt exec} command.  When the program exits, you are
logged out.

\pagebreak
So if you want to list your files and then logout, you can type into
your login window:
\newline {} \newline
{\tt \% exec ls}
\newline {} \newline
{\it files list here}
\newline {} \newline
and the next thing you see is...
\newline {} \newline
{\tt Project Athena (foobar)\footnote{If you want to know what
foobar means, ask a hacker.  Or track down a copy of {\bf The
Hacker's Dictionary}.}
\newline {} \newline
login:
}
\subsubsection{Ending your input file}

Typing {\tt C-d} at the shell will log you off. It's simple, neat, and
clean.  The {\tt C-d} character means ``end-of-file.'' Typing {\tt C-d} tells
the program (the shell) reading the input stream (from your keyboard)
``Hey, there's no more input coming down this pipe.''

Since there's nothing else for the shell to read, it exits:
\begin{verbatim}
% C-d
logout
\end{verbatim}

In the early days of UNIX, many users typed {\tt C-d} by accident. So
the csh was modified to ignore {\tt C-d} if a particular shell variable,
``ignoreeof'', had been set:
\begin{verbatim}
% set ignoreeof
% C-d
Use "logout" to logout.
%
\end{verbatim}

What to do? Two things: First, you can type {\tt unset ignoreeof}, and
undo the damage that was done the first time ({\tt set ignoreeof} is
probably in your {\it .login} or {\it .cshrc} file, so if you're serious
about getting rid of ``ignoreeof,'' check in those files and remove that
line.).  Alternatively, you can be persistent and type {\tt C-d} 25
times.  The 25\super{th} time, {\tt C-d} logs you out.  (Can you figure out
why?)

Of course, if you unset ``ignoreeof'', you will no longer be protected
from accidentally typing one {\tt C-d} too many.  If you just want a
quick way to log out, alias logout to ``lo,'' which is harder to type by
accident (to do this, type {\tt alias lo 'logout'}).

% Local Variables:
% mode: TeX
% version-control: t
% make-backup-files: t
% End:
