354
Networking: A Beginner's Guide
top: Show an Interactive List of Processes
The top command is an interactive version of ps. Instead of giving a static view of what is
going on, this tool refreshes the screen with a list of processes every two or three seconds
(the user can adjust the interval). From this list, you can reprioritize or kill processes.
The key problem with the top program is that it is a CPU hog. On a congested
system, this program tends to make memory problems worse as users start running
top
to see what is going on, only to find several other people are running it as well.
Collectively, they have made the system even slower than before!
By default, top installs with permissions granted to all users. You might find it
prudent, depending on your environment, to allow only root to be able to run it. To do
this, change the permissions for the top program with the following command:
[root@ford /root]# chmod 0700 /usr/bin/top
kill: Send a Signal to a Process
For some reason, the kill program was horribly named. The program doesn't really kill
processes! What it does is send signals to running processes. By default, the operating
system supplies each process a standard set of signal handlers to deal with incoming
signals. From a systems administrator's standpoint, the most important handler is for
signal numbers 9 and 15: kill process and terminate process. (Okay, maybe using kill as
a name wasn't so inappropriate after all. )
When kill is invoked, it requires at least one parameter: the process identification
number (PID) as derived from the ps command. When passed only the PID number,
by default, kill will send signal 15, terminate process. Sending the terminate process
signal is a lot like politely asking a process to stop what it's doing and shut down.
Some programs intercept this signal and perform a number of actions so that they can
cleanly shut down; others just stop in their tracks. Either way, sending the signal isn't a
guaranteed method for making a process stop.
The optional parameter is a number prefixed by a dash (-), where the number
represents a signal number. The two signals that systems administrators are most
interested in are 9 and 1: kill and hang up. The kill signal is the impolite way of making
a process stop. Instead of asking a process to stop, the operating system takes it upon
itself to kill the process. The only time this signal will fail is when the process is in the
middle of a system call (such as a request to open a file), in which case the process will
die once it returns from the system call.
The hangup signal is a bit of a throwback to when most users of UNIX connected
to the system via VT100-style terminals. When a user's connection would drop in
the middle of a session, all of that user's running processes would receive a hangup
signal (often called a SIGHUP, or HUP for short). This signal gave the processes an
opportunity to perform a clean shutdown or, in the case of some programs designed
to keep running in the background, to safely ignore the signal. These days, the hangup
(HUP) signal is used to tell certain server applications to reread their configuration
files. Most applications otherwise ignore the signal.
For example, to terminate process number 2059, type the following:
[root@ford /root]# kill 2059