Information on Processes: ps and pstree

These two commands display a list of processes currently running 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
     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: 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 at which 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 the most 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.

pstree

The pstree command displays 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 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 the process. Because the tree structure is generally quite long, you will want to invoke pstree in the following way:

     $ pstree -up | less
    

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