Linux-Mandrake:
User Guide and
Reference Manual

MandrakeSoft

 
 
January 2000
http://www.linux-mandrake.com


Next : Where to get documentation
Previous : Lothar
Up

(Back to the table of contents)

Chapter 7 : Process control


More about processes

In a previous section, we mentioned that it was possible to monitor processes; that is what we will cover next. To understand the operations we are going to perform here, it is helpful to know a bit more about them.

Process Tree

As with files, all processes that run on a Linux system are organized in the form of a tree, and each process has a number (its PID, Process ID), together with the number of its parent process (PPID, Parent Process ID).

This means that there is a process at the top of the tree structure, the equivalent of the root for filesystems: init (see Reference manual), which is always numbered 1. The next section will explain two commands, ps and pstree, which allow you to obtain information on a running process.

Signals

Every process in Unix can react to signals sent to it. There exist 31 different signals. For each of these signals, the process can reset the default behavior, except for two signals: signal number 9 (KILL), and signal number 19 (STOP).

Signal 9 kills a process irrevocably, without giving it the time to terminate properly. This is the signal you send to a process which is stuck or exhibits other problems. A full list of signals is available using the command kill -l.

Obtaining information on processes: ps and pstree

These two commands display a list of processes present on the system according to criteria set by you.

ps

Sending this command without an argument will show only processes initiated by you and attached to the terminal you are using:

$ ps
  PID TTY          TIME CMD
 5162 ttya1    00:00:00 zsh
 7452 ttya1    00:00:00 ps

There are a large number of options, of which we will look at the most common:

There are many other options. Refer to the manual page for more information (man ps).

The output of this command is divided into different fields: the one that will interest you the most is the field PID, which contains the process identifier. The field CMD contains the name of the command executed.

A very common way of calling up ps is as follows:

$ ps ax | less

This gets you a list of all processes currently running, so that you can identify one or more processes which are causing problems and subsequently kill them.

pstree

The command pstree displays the processes in the form of a tree structure. One advantage is that you can immediately see what is the parent process of what: when you want to kill a whole series of processes and if they are all parents and children, you simply kill the parent. You want to use the option -p, which displays the PID of each process, and the option -u which displays the name of the user who started off the process. As the tree structure is generally long, you want to call up pstree in the following way:

$ pstree -up | less

This gives you an overview of the whole process tree structure.

Sending signals to processes: kill, killall and top

Shortcut in X: xkill

If you are using KDE, there is a shortcut for killing a blocked X process. There is a very easily identifiable icon on the desktop, reproduced in figure 10.1.

xkill icon
Figure 10.1 xkill icon

This icon activates the command xkill which you can run from a terminal. When you click on this icon (or start the program from your terminal), the mouse cursor changes. You then left-click on the window corresponding to the process you want to kill.

kill, killall

These two commands are used to send signals to processes. The command kill requires a process number as an argument, while killall requires a command name.

The two commands can optionally receive a signal number as an argument. By default, they both send the signal 15 (TERM) to the relevant process(es). For example, if you want to kill the process with PID 785, you enter the command:

$ kill 785

If you want to send it signal 9, you enter:

$ kill -9 785

Suppose that you want to kill a process for which you know the command name. Instead of finding the process number using ps, you can kill the process directly:

$ killall -9 netscape

Whatever happens, you will only kill your own processes (unless you are root), so don't worry about the "neighbor's" processes with the same name, they will not be affected.

top

top is a program all in one: it simultaneously fulfils the functions of ps and kill. It is a console mode program, so you start it from a terminal, like it is shown in figure 10.2.

Example of execution of top
Figure 10.2 Example of execution of top

The program is entirely keyboard controlled. You can access help by pressing 'h'. Here are some of the commands you can use.


Next : Where to get documentation
Previous : Lothar
Up

Copyright � 2000 MandrakeSoft