pstree

processLinux/Unix
The pstree command is one of the most frequently used commands in Linux/Unix-like operating systems. pstree Display a tree of processes

Quick Reference

Command Name:

pstree

Category:

process

Platform:

Linux/Unix

Basic Usage:

pstree [options] [arguments]

Common Use Cases

    Syntax

    pstree [options] [pid|user]

    Options

    Option Description
    -a Show command line arguments
    -A Use ASCII line drawing characters
    -c Disable compaction of identical subtrees
    -G Use VT100 line drawing characters
    -h Highlight current process and its ancestors
    -H pid Highlight the process with the specified PID
    -l Display long lines (don't truncate)
    -n Sort by PID instead of by name
    -p Show PIDs in the tree
    -s Show parents of the selected process only
    -S Show namespaces transitions
    -T Hide threads
    -u Show uid transitions
    -U Use UTF-8 line drawing characters
    -V Display version information
    -Z Show SELinux security contexts

    Examples

    How to Use These Examples

    The examples below show common ways to use the pstree command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    Basic Examples:

    pstree
    Display all processes in a tree.
    pstree -p
    Display process IDs in the tree.
    pstree 1
    Show process tree starting from init (PID 1).
    pstree $USER Show process tree for the current user.

    Advanced Examples:

    pstree -p -a Show process IDs and command line arguments. pstree -h Highlight the current process and its ancestors. pstree -u Show uid transitions in the process tree. pstree -T Hide threads from the tree display. pstree -n Sort processes by PID instead of by name. pstree -l 3 Set maximum depth of the tree to 3 levels. pstree -p | grep firefox Find firefox in the process tree, showing PIDs. pstree -p -s 1234 Show parents and the specified process only.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The `pstree` command is a visual process listing utility that displays running processes in a tree-like format, showing the parent-child relationships between processes. This hierarchical view makes it easier to understand the process structure of a system compared to flat listings provided by commands like `ps`. In Unix-like operating systems, processes form a tree structure. Every process (except the initial process, usually with PID 1) has a parent process that spawned it. The `pstree` command visualizes this hierarchy, providing a clear picture of how processes relate to each other. Key features and benefits of `pstree` include: 1. Hierarchical Visualization: The tree structure clearly shows which processes launched other processes, making it easier to trace the origin of any process. 2. Process Grouping: Related processes are grouped together, making it easier to understand which processes belong to the same application or service. 3. Compact Representation: By default, identical branches of the process tree are merged and marked with a count in brackets, reducing clutter in the output. 4. Selective Display: You can focus on specific parts of the process tree by specifying a starting PID or username. 5. Process Details: With various command-line options, you can display PIDs, command-line arguments, and other process attributes within the tree structure. 6. Troubleshooting Aid: The command is particularly useful for debugging, identifying runaway processes, or understanding complex service architectures. Typical use cases for `pstree` include: - System administration tasks where understanding process relationships is important - Debugging applications to see what child processes they've spawned - Identifying resource usage patterns by related groups of processes - Educational purposes to understand how processes are organized in Unix-like systems - Quickly finding the parent of a problematic process Unlike the `ps` command, which can show detailed information about individual processes but doesn't clearly display relationships, `pstree` focuses on making the hierarchy clear. For more detailed process information, `ps` or `top` would be more appropriate tools to use alongside `pstree`. The `pstree` command is part of the `psmisc` package in most Linux distributions and is also available on other Unix-like systems.

    Related Commands

    These commands are frequently used alongside pstree or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the pstree command works in different scenarios.

    $ pstree
    View All Commands