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
- Process visualization
- System analysis
- Process relationships
- Debugging
- 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
Full process info:
pstree -ap
Highlight process:
pstree -h -p pid
Show arguments:
pstree -a
Performance Analysis
- Process table reading
- Tree construction
- Display formatting
- Memory usage
- Update frequency
Additional Resources
Display Options
- ASCII art
- UTF-8 characters
- Color highlighting
- Line compaction
- Sort ordering
Best Practices
- Use appropriate display mode
- Consider terminal width
- Show relevant information
- Regular monitoring
- Document unusual patterns