These two commands display a list of processes currently running 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 |
As with many UNIX utilities, ps has a handful of options, we will look at the most common here:
a: also displays processes started by other users;
x: also displays processes with no control terminal or with a control terminal different to the one you are using;
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 ps(1) manual page for more information.
The output of this command is divided into different fields: the one that will interest you 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 invoking ps is as follows:
$ ps ax | less |
The command pstree displays the processes in the form of a tree structure. One advantage is that you can immediately see which 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 can 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 invoke pstree in the following way:
$ pstree -up | less |