How to use pstree command.

How To Use Pstree Command.

In this article, we will talk about the pstree command. It is similar to ps , but instead of listing the running processes, it shows them in a tree. The tree-like format is a more convenient way to display the processes hierarchy and makes the output more visually appealing.

When working on a Linux machine, sometimes you might need to find out what processes are currently running. There are number of commands that you can use to find information about the running processes, with ps and top being the most commonly used ones.


How to Use the pstree Command

The general syntax for the pstree command is as follows:


If you encounter the below error while running the pstree command:

pstree: command not found

you may try installing the package as shown below as per your choice of distribution.




brew install pstree


apt-get install psmisc


apt-get install psmisc


apk add psmisc

Arch Linux

pacman -S psmisc

Kali Linux

apt-get install psmisc


yum install psmisc


dnf install psmisc


apt-get install psmisc

In it’s simplest form when invoked without any option or argument, pstree displays a hierarchical tree structure of all running processes:

        │        └─qmgr
        │      └─sshd───sshd

The top/root item in the tree is the parent process of all system processes. In this example that is systemd, which is the first process that start on boot.

pstree merges identical branches by putting them between square brackets and prefixing them with an integer that represents the number of branches. This makes the output more readable and visually appealing.

Below is an example showing how the square brackets are used:


is same as:


To disable the merging of the identical branches, use the -c option:

pstree -c

The threads of a process are shown under the parent process and displayed using the process name inside curly braces. Here is an example:


Use the -t option to show the full threads names. If you want to hide threads and show only processes use the -T option.

Typically, pstree displays many lines of output that doesn’t fit on the screen. To view the output one page at a time, pipe it to the less command:

pstree | less

If a user name is given as an argument, pstree shows only the processes owned by that user. For example, the following command will show only those processes that have been started by a user named “linuxize”:

pstree root

When PID is specified as an argument, pstree displays a tree with the given process as the root of the tree. Here is an example:

pstree 1943

To show the parent processes of the given process use the -s option followed by the process PID:

pstree -s 1943


Show PIDs and PGIDs

Usually, when running the pstree command, the most important information the user is looking for is the process ID. For example, knowing the PID allows you to kill a malfunctioning process .

The -p option instructs pstree to show the PIDs:

pstree -p

PIDs are shown in parentheses after each process or thread.

           │              └─qmgr(1307)

By default, pstree, sort processes with the same parent by name. The -n option tells pstree to use numeric sort, i.e. sort by PIDs:

pstree -pn

The process group ID or PGIDs is the process ID of the first member of the process group. To view PGIDs use the -g option:

pstree -g

PIDs are also shown in parentheses after each process or thread.

           │                  ├─{VBoxService}(954)
           │                  ├─{VBoxService}(954)
           │                  ├─{VBoxService}(954)
           │                  ├─{VBoxService}(954)
           │                  ├─{VBoxService}(954)
           │                  └─{VBoxService}(954)

When PIDs or PGIDs are shown, merging is implicitly disabled.


Show Command Line Arguments

Some programs can be invoked with configuration options specified as command-line arguments.

By default, the pstree does not show you the command line arguments for the running processes. To view how the process was started, use the command together with the -a option:

pstree -a
  ├─agetty -o -p -- \\u --keep-baud 115200,38400,9600 ttyS0 vt220
  ├─agetty -o -p -- \\u --noclear tty1 linux



pstree also allows you to highlight processes for better visual representation.

The -h option instructs pstree to highlight the current process and all its ancestors.

pstree -h

To highlight a specific process, use the -H option followed by the process ID:

pstree -H PID_NUMBER

If the highlighting is not supported, the command will exit with an error.



The pstree command displays the running processes in the form of a tree structure.

For information about all available pstree options, type man pstree in your terminal.