pstree command in Linux with examples

This pstree command guide is a follow-up of my previous 90 Linux Commands frequently used by Linux Sysadmins article. Every week, or as time allows, I will publish articles on the ~ 90 commands geared toward Linux sysadmins and Linux power users. Let’s continue this series with the pstree command.


pstree command and examples

Pstree is a convenient Linux command used to show running processes in a tree (data structure). If a user name is specified, all process trees rooted at processes owned by that user are shown. Pstree is used as an alternative to the ps command. The pstree command is usually included in Linux distributions. Otherwise, it can be installed using psmisc package For example, yum install psmisc.

pstree -p example


pstree command examples:

The basic syntax for pstree is:

pstree [options] [pid or username]

To display all process trees rooted at processes owned by a specific user with their PIDs, use:

pstree -p username

To display a tree of processes, use:


To display a tree of processes with PIDs, use:

pstree -p

To sort processes by PID instead of by name, use:

pstree -np

To wrap long lines, use:

pstree -l


pstree options (man pstree)

-a Show command line arguments. If the command line of a process is swapped out, that process is shown in parentheses. -a implicitly disables compaction for processes but not threads.
-A Use ASCII characters to draw the tree.
-c Disable compaction of identical subtrees. By default, subtrees are compacted whenever possible.
-C Color the process name by a given attribute. Currently, pstree only accepts the value age which colors by process age. Processes newer than 60 seconds are green, newer than an hour yellow, and the remaining red.
-g Show PGIDs. Process Group IDs are shown as decimal numbers in parentheses after each process name. -g implicitly disables compaction. If both PIDs and PGIDs are displayed then PIDs are shown first.
-G Use VT100 line-drawing characters.
-h Highlight the current process and its ancestors. This is a no-op if the terminal doesn’t support highlighting or if neither the current process nor any of its ancestors are in the subtree being shown.
-H Like -h, but highlight the specified process instead. Unlike with -h, pstree fails when using -H if highlighting is not available.
-l Display/wrap long lines. By default, lines are truncated to either the COLUMNS environment variable or the display width. If neither of these methods work, the default of 132 columns is used.
-n Sort processes with the same parent by PID instead of by name. (Numeric sort.)
-N Show individual trees for each namespace of the type specified. The available types are ipc, mnt, net, pid, time, user, uts.
-p Show PIDs. PIDs are shown as decimal numbers in parentheses after each process name. -p implicitly disables compaction.
-s Show parent processes of the specified process.
-S Show namespaces transitions. Like -N, the output is limited when running as a regular user.
-t Show full names for threads when available.
-T Hide threads and only show processes.
-u Show uid transitions. Whenever the uid of a process differs from the uid of its parent, the new uid is shown in parentheses after the process name.
-U Use UTF-8 (Unicode) line drawing characters. Under Linux 1.1-54 and above, UTF-8 mode is entered on the console with echo -e ' 33%8' and left with echo -e' 33%@'.
-V Display version information.
-Z Show the current security attributes of the process. For SELinux systems, this will be the security context.

pstree example

Pstree makes it very easy to find parent processes. The root of the tree is either init or the process with the given PID. As a reminder, the psmisc package contains a small set of utilities that use the proc file-system: fuser, killall, prtstat, pslog, peekfd, and yes pstree.

pstree useful reading:

pstree alternative/related commands:

  • ps – information about the currently running processes.
  • lsof –  LiSt Open Files – display any open files.
  • top – shows an overall system view.
  • pgrep – find process IDs of a running program.

Top ↑