How to View the Process Hierarchy in Linux Using the pstree Command

When you run the standard top or ps commands in Linux, you are presented with a flat list of running processes. While this is useful for identifying high CPU usage, it tells you nothing about the relationships between those processes. You cannot easily see which application spawned which background worker thread.

To truly understand how applications are executing and interacting on your system, you need to view them as a “tree.” The pstree command does exactly this, visually mapping out the parent-child hierarchy of every active process.

How to Use the pstree Command

The command is likely already installed on your system. Simply open a terminal and execute it without any arguments:

pstree

You will see a visual representation of your system, starting with the root initialization process (usually systemd or init) branching out into major services (like sshd or apache2), which then branch out further into individual worker threads.

Useful Flags and Options

To make the output significantly more useful for troubleshooting, you should append a few specific flags.

1. Show Process IDs (PIDs)

If you identify a frozen process in the tree that you want to kill, you need its PID. By default, pstree only shows names. Use the -p flag to force it to display the PID in parentheses next to every single branch.

pstree -p

2. Focus on a Specific User

If you are on a multi-user server and only want to see the processes spawned by a specific colleague (or a specific service account), you can pass their username as an argument.

pstree johndoe

3. Focus on a Specific Application

If you are troubleshooting a web server and want to see exactly how many worker threads it has spawned, you can pass the PID of the master process. For example, if you know your Nginx master process has a PID of 1050:

pstree -p 1050

This will filter out the rest of the system and only draw the tree starting from that specific Nginx application.

Get the best tech tips delivered straight to your inbox.

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