Last Updated : 09 Oct, 2024
The pstree command in Linux is a powerful tool that displays running processes as a tree structure. This visual representation makes it easier to understand the hierarchy of processes, providing a more intuitive view of how processes are related to each other. The root of the tree is either the `init` process or a process with a specified PID. While pstree comes pre-installed on most Linux distributions, it can also be installed on other Unix-like systems.
Syntaxpstree [options] [pid or username]Basic Pstree Example
To display the basic process tree, simply run the pstree command without any options:
Output:
This output shows the hierarchical relationship between processes, with child processes indented under their parent processes.
Key Options of the pstree CommandOption
Description
-a
Show command line arguments
-p
Show PIDs
-c
Disable compaction of identical subtrees
-n
Sort processes with the same parent by PID
-u
Show uid transitions
-h
Highlight current process and its ancestors
-g
Show PGID numbers
-V
Display version information
1. Display Command Line Arguments (-a)To include command line arguments in the output:
-a optionOutput:
outputThis output shows more detailed information about each process, including the command line arguments used to start them.
2. Display PIDs (-p)To show Process IDs (PIDs) for each process:
-p option 3. Disable Compaction of Identical Subtrees (-c)By default, `pstree` compacts identical branches. Use the `-c` option to expand all subtrees:
Disable Compaction of Identical Subtrees 4. Sort Processes by PID (-n)To sort processes with the same parent by PID instead of by name:
Sort Processes by PID 5. Show User/Owner of Processes (-u)To display the owner of each process:
Show User/Owner of Processes 6. Highlight Current Process (-h)To highlight the current process and its ancestors:
Highlight Current Process 7. Show Process Group IDs (-g)To display process group IDs:
Show Process Group IDs Advanced Usages of pstree Command 1. Display Process Tree for a Specific UserTo show all process trees rooted at processes owned by a specific user:
Display Process Tree for a Specific UserReplace `username` with the actual username you want to investigate.
2. Display Version InformationTo check the version of `pstree` installed on your system:
Display Version InformationOutput:
Output ConclusionThe pstree command is a versatile tool for visualizing and analyzing the process hierarchy in Linux systems. Its various options allow users to customize the output to suit their needs, whether it's identifying process relationships, troubleshooting, or system monitoring. By mastering `pstree`, system administrators and power users can gain valuable insights into their system's process structure and behavior.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4