It's My Process, and I'll Do What I Want To

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.
At the command prompt, type ps -a.

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).

Figure 11.3. To view all running processes that are associated with a terminal, enter ps -a.


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.

Figure 11.4. To monitor all processes, pipe ps -aux to more.


ps -aux Columns
FieldMeaning
USERUser name of the process owner
PIDProcess ID
%CPUPercentage of the CPU this process is using
%MEMPercentage of memory this process is using
VSZVirtual size of the process, in kilobytes
RSSAmount of physical memory used by the process
TTYAssociated terminal.
STATStatus 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)
STARTTime the process was started
TIMECPU time the process has consumed
COMMANDCommand 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.

Figure 11.5. Enter killall -v to kill a process by name and receive confirmation.


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).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.37.191