These two commands display a list of processes present on the system according to criteria set by you.
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:
a: also displays processes started by other users;
x: also displays processes with no control terminal (this applies to almost all servers);
u: displays for each process the name of the user who started it and the time it was started.
There are many other options. Refer to the manual page for more information (man 1 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.
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.