LinuxCommandLibrary

pstree

Display processes as a tree

TLDR

Display a tree of all processes (rooted at init)

$ pstree
copy

Display a tree of processes with PIDs
$ pstree [[-p|--show-pids]]
copy

Display all process trees rooted at processes owned by specified user
$ pstree [user]
copy

Display command line arguments
$ pstree [[-a|--arguments]]
copy

Display children of a specified process
$ pstree [pid]
copy

Display parents of a specified process
$ pstree [[-s|--show-parents]] [pid]
copy

SYNOPSIS

pstree [options] [pid | user]

PARAMETERS

-a
    -a
Show command-line arguments. By default, pstree only shows the command name. This can make the output very wide.

-c
    -c
Disable compact mode. This prevents pstree from compacting identical subtrees into a single entry with a count (e.g., "{httpd,3}").

-h
    -h
Highlight the current process and its ancestors in the tree. This helps quickly locate your current shell or script within the hierarchy.

-g
    -g
Show PIDs as process group IDs. Instead of individual PIDs, this option displays the process group ID in parentheses.

-l
    -l
Long lines. Don't truncate long lines, showing full command paths and arguments when used with -a.

-n
    -n
Sort processes by PID numerically instead of by name. This can alter the visual order of sibling processes.

-p
    -p
Show PIDs. Displays the Process ID in parentheses after each process name.

-u
    -u
Show UIDs. Displays the effective User ID in parentheses after each process name.

-T
    -T
Don't draw branches for single children. This creates a more linear, less branched output for direct parent-child relationships where a parent has only one child.

-V
    -V
Display version information and exit.

pid
    The PID of a specific process. pstree will display the subtree starting from this process and its descendants only.

user
    The username. pstree will display the tree for processes owned by this specified user only.

DESCRIPTION

pstree is a command-line utility that displays running processes in a hierarchical, tree-like format. Unlike the ps command, which provides a flat list of processes, pstree visually represents parent-child relationships, making it easy to understand which processes were started by which others. This hierarchical view is particularly useful for debugging, system monitoring, and understanding process dependencies.

It typically starts the tree from init (PID 1) or systemd, showing all its descendants. Users can specify a particular PID or username to view only the subtree originating from that point. The output can be customized to show Process IDs (PIDs), command-line arguments, or User IDs (UIDs).

CAVEATS

pstree relies on information from the /proc filesystem. If /proc is not correctly mounted or accessible (e.g., in some chroot or container environments), pstree may not function as expected or provide incomplete information. The output represents a snapshot at the time the command is executed, not a real-time view. On systems with many processes, the output can be very extensive and scroll rapidly, potentially making it hard to read without piping to a pager like less.

COMPACT MODE

By default, pstree condenses identical branches by showing a count in curly braces (e.g., "{httpd,3}" means three identical httpd processes). This behavior helps reduce clutter in the output. Use the -c option to disable this compaction and show every process individually.

COLOR OUTPUT

Some versions of pstree support colorized output, which can be enabled via environment variables (e.g., LS_COLORS or specific PSTREE_COLORS settings) or through specific terminal configurations. This can enhance readability, especially when highlighting processes with the -h option, making it easier to distinguish different parts of the tree.

HISTORY

pstree is part of the psmisc package, a collection of utilities for displaying and manipulating processes. It has been a standard utility in most Linux distributions for many years, providing a crucial visual complement to the more tabular output of commands like ps. Its development aimed to offer a more intuitive way to understand process relationships, which is fundamental for system administration and troubleshooting.

SEE ALSO

ps(1), top(1), htop(1), kill(1), proc(5)

Copied to clipboard