2. Information on Processes: ps and pstree

These two commands display a list of processes currently running on the system, according to the criteria you set. pstree has a cleaner output when compared to ps -f.

2.1. ps

Running ps without arguments will show only processes initiated by you and attached to the terminal you are using:

$ ps
       PID TTY          TIME CMD
     18614 pts/3    00:00:00 bash
     20173 pts/3    00:00:00 ps

As with many UNIX® utilities, ps has a handful of options, the most common of which are:

  • a: displays processes started by all users;

  • x: 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 at which it was started.

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

The output of ps is divided into different fields: the most interesting one is the PID field which contains the process identifier. The CMD field contains the name of the executed command. A very common way of invoking ps is as follows:

$ ps ax | less

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

2.2. pstree

The pstree command displays processes in the form of a tree structure. One advantage is that you can immediately see the processes' parents: 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 will want to use the -p option to display the PID of each process, and the -u option to show the name of the user who started it. Because the tree structure is generally quite long, you should invoke pstree in the following way:

$ pstree -up | less

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