Perhaps you've had the experience in Microsoft Windows of a rogue program that will not stop running, or a window that is plastered in an open position on the screen and will not close. The only way to close the program or window is to press Ctrl+Alt+Del. (This is sometimes called a three-fingered salute.)
Ctrl+Alt+Del opens the Close Program dialog box in Microsoft Windows. The Close Program dialog box probably reports that the errant program as not responding. To stop it, you select the program and click End Task. (True: There is one other way, too—turning off the power.)
As a Linux administrator or developer, you may need to perform an analogous job. In Linux, this job is not known as ending a task but, rather, as killing a process.
In Linux, process is shorthand for an abstraction that manages the memory, CPU, and input and output resources necessary to run a program. Although Linux gives the impression that many things are happening simultaneously, in fact, only one process can be executing on one CPU at any given instant. The illusion of simultaneous execution of processes is achieved through time slicing, in which the operating system changes the process that is active at regular, very short intervals.
To view all processes associated with a terminal:
1. | Log on as root. |
2. | |
3. | Press Enter. A table will appear (Figure 11.3), showing the process ID (PID), the terminal that originated the process (TTY), the CPU time that the process has consumed (TIME), and the command that started the process (COMMAND). |
To monitor all processes:
1. | Log on as root. |
2. | At the command prompt, type ps -aux | more |
3. | Press Enter. A screen-by-screen display will appear (Figure 11.4). For an explanation of the columns, see Table 11.2. |
4. | Use the spacebar to scroll through the screens. |
ps -aux Columns | |
---|---|
Field | Meaning |
USER | User name of the process owner |
PID | Process ID |
%CPU | Percentage of the CPU this process is using |
%MEM | Percentage of memory this process is using |
VSZ | Virtual size of the process, in kilobytes |
RSS | Amount of physical memory used by the process |
TTY | Associated terminal. |
STAT | Status of the process; some values are: |
R (Runnable) | |
D (In disk wait state) | |
I (Sleeping for less than 20 seconds) | |
S (Sleeping for more than 20 seconds) | |
T (Stopped) | |
Z (Zombie, an orphaned process that should have previously been killed by another process) | |
W (Process that is swapped out) | |
N (Nice value, which influences the execution priority of the process) | |
START | Time the process was started |
TIME | CPU time the process has consumed |
COMMAND | Command name (and its arguments) that started the process |
To kill a process:
1. | Log on as root (or as the owner of the process). |
2. | At the command prompt, type kill followed by the process ID (PID). For example, type kill 856. |
3. | Press Enter. |
Tip
Only root—or the owner of a process—can kill a process.
Tip
Process IDs vary from session to session for the same program. Be careful about what you kill!
To kill a process by name, with confirmation:
1. | Log on as root (or as the process owner). |
2. | At the prompt, type killall -v processname For example, type killall -v postmaster |
3. | Press Enter. The system will respond with a message reporting that the process has been killed (Figure 11.5). |
3.138.37.191