Tracking Down Processes (Unix Power Tools, 3rd Edition)
24.7. Tracking Down Processes
ps without arguments lists all processes
started from the current terminal or pseudo-terminal. But since
ps is not a shell command, it
doesn't correlate process IDs with the
shell's job numbers. It also
doesn't help you find the ID of the runaway process
in another shell window.
To get this information, use
ps
-a (for "all");
this lists information on a different set of processes, depending on
your Unix version.
24.7.1. System V
Instead of listing all that were started
under a specific terminal, ps -a
on System V-derived systems lists all processes associated with any
terminal that aren't group leaders. For our
purposes, a "group leader" is the
parent shell of a terminal or window. Therefore, if you are using a
windowing system, ps -a lists all
jobs started in all windows (by all users), but not their parent
shells.
Assume that, in the previous example, you have only one terminal or
window. Then ps -a will print the
same output as plain ps except for the first line,
since that's the parent shell. This
doesn't seem to be very useful.
But consider what happens when you have multiple windows open.
Let's say you have three windows, all running
terminal emulators such as xterm for the X Window
System. You start background jobs alice,
duchess, and hatter in windows
with pseudo-terminal numbers 1, 2, and 3, respectively. This
situation is shown in Figure 24-1.
Figure 24-1. Background jobs in multiple windows
Assume you are in the uppermost window. If you type
ps, you will see something like this:
PID TTY TIME COMD
146 pts/1 0:03 bash
2349 pts/1 0:03 alice
2390 pts/1 0:00 ps
But if you type ps -a, you will
see this:
PID TTY TIME COMD
146 pts/1 0:03 bash
2349 pts/1 0:03 alice
2367 pts/2 0:17 duchess
2389 pts/3 0:09 hatter
2390 pts/1 0:00 ps
Now you should see how ps -a can
help you track down and kill (Section 24.12) a runaway process. If it's
hatter, you can type kill 2389.
If that doesn't work, try kill
-QUIT 2389, or in the worst case, kill
-KILL 2389.
24.7.2. BSD
On BSD-derived systems,
ps -a lists all jobs that were
started on any terminal; in other words, it's a bit
like concatenating the the results of plain ps for
every user on the system. Given the above scenario,
ps -a will show you all processes
that the System V version shows, plus the group leaders (parent
shells).
Unfortunately, ps -a (on any
version of Unix) will not report processes that are in certain
conditions where they "forget"
things such as what shell invoked them and what terminal they belong
to. Such processes are known as zombies or
orphans (Section 24.19). If you have a serious runaway process
problem, it's possible that the process has entered
one of these states.
You need another option to ps to see it: on
System V, it's
ps
-e ("everything");
on BSD, it's
ps -ax.
These options tell ps to list processes that
either weren't started from terminals or
"forgot" what terminal they were
started from. The former category includes lots of basic processes
that run the system and daemons
(Section 1.10) that handle system services like mail,
printing, network file systems, etc.
In fact, the output of ps -e or
ps -ax is an excellent source of
education about Unix system internals. Run the command on your system
and, for each line of the listing that looks interesting, invoke
man (Section 2.1)
or info (Section 2.9) on the process name.
User shells and processes are listed
at the very bottom of ps -e or
ps -ax output; this is where you
should look for runaway processes. Notice that many
processes in the listing have ? instead of a
terminal. Either these aren't supposed to have a
terminal (such as the basic daemons), or they're
runaways. Therefore it's likely that if
ps -a doesn't
find a process you're trying to kill,
ps -e or ps
-ax will list it with ? in the
TTY (or TT) column. You can determine which process you want by
looking at the COMD (or COMMAND) column.
Section 24.22 shows a similar thing: how to
close windows by killing their
process.
--CN and BR
24.6. The Controlling Terminal24.8. Why ps Prints Some Commands in Parentheses
Copyright © 2003 O'Reilly & Associates. All rights reserved.
Wyszukiwarka
Podobne podstrony:
ch24 (9)ch24 (16)ch24ch24 (10)ch24ch24ch24 (8)ch24CH24ch24ch24 (5)ch24 (13)CH24 (12)ch24ch24ch24 (6)ch24!ch24!ch24więcej podobnych podstron