pstree

Overview

The pstree command displays running processes as a tree. It shows the process hierarchy, making parent-child relationships between processes clear.

Syntax

pstree [options] [pid|user]

Common Options

Option Description
-a Show command line arguments
-c Don’t compact identical subtrees
-h Highlight current process
-H pid Highlight specified process
-l Long lines
-n Sort by PID
-p Show PIDs
-u Show uid transitions
-Z Show security context
-A Use ASCII characters
-U Use UTF-8 characters

Key Use Cases

  1. Process visualization
  2. System analysis
  3. Process relationships
  4. Debugging
  5. System monitoring

Examples with Explanations

Example 1: Basic Usage

pstree

Show process tree

Example 2: Show PIDs

pstree -p

Show process tree with PIDs

Example 3: User Processes

pstree username

Show user’s process tree

Understanding Output

Example output:

systemd─┬─systemd-journal
        ├─systemd-udevd
        ├─sshd─┬─sshd───bash
        │      └─sshd───sftp-server
        └─nginx─┬─nginx
                └─nginx

Common Usage Patterns

  1. Full process info:

    pstree -ap
  2. Highlight process:

    pstree -h -p pid
  3. Show arguments:

    pstree -a

Performance Analysis

  • Process table reading
  • Tree construction
  • Display formatting
  • Memory usage
  • Update frequency

Additional Resources

Display Options

  1. ASCII art
  2. UTF-8 characters
  3. Color highlighting
  4. Line compaction
  5. Sort ordering

Best Practices

  1. Use appropriate display mode
  2. Consider terminal width
  3. Show relevant information
  4. Regular monitoring
  5. Document unusual patterns