How to Display the Process Tree Using the pstree Command in Linux

When you use standard Linux process monitoring tools like ps or top, you are presented with a flat, chaotic list of hundreds of active processes. While these tools are excellent for checking CPU usage, they fail to demonstrate the critical relationships between the programs. In Linux, processes are hierarchical; a “parent” process spawns “child” processes. If an apache web server spawns twenty unresponsive child threads, a flat list will just show you twenty random apache processes. To instantly visualize exactly which process spawned which, you must use the pstree command.

How to View the Process Tree

The pstree utility is part of the psmisc package, which is installed by default on almost all modern Linux distributions. To use it, simply type the command into your terminal.

pstree

The output is a visually structured, ASCII-art tree. At the very far left, you will see the absolute root of the tree (usually systemd or init, the very first process started when the server booted). Branching out to the right, you will see the child processes, and branching off them, their respective sub-children.

Showing Process IDs (PIDs)

By default, pstree only shows the human-readable names of the processes (e.g., sshd, bash, nginx). If your goal is to find a rogue child process so you can forcefully kill it, you need its exact Process ID (PID). You can force pstree to display the PID next to every single branch using the -p flag.

pstree -p

The output will now look like this: sshd(1024)---bash(1025)---python3(2048). This immediately tells you that the SSH daemon (1024) launched a bash shell (1025), which then executed a Python script (2048).

Highlighting the Current Process

If you are SSH’d into a massive server with thousands of active processes, finding your specific terminal session in the massive tree can be tedious. You can use the -h (highlight) flag.

pstree -h

This will print the entire process tree, but the specific lineage of processes that led to your current pstree command will be highlighted in bold text, allowing you to instantly locate yourself within the system hierarchy.

Focusing on a Specific User

If you share a server with multiple developers and you only want to see the processes belonging to a specific user (e.g., ‘john’), you can append their username as an argument.

pstree john

This command completely strips away the global system processes (like background daemons and root services) and draws a clean, isolated tree showing only the applications currently being executed by John.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.