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.
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.
Syntax
pstree [options] [pid or username]Key Options of the pstree Command
Option | 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:

Output:

This 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:

3. Disable Compaction of Identical Subtrees (-c)
By default, `pstree` compacts identical branches. Use the `-c` option to expand all subtrees:

4. Sort Processes by PID (-n)
To sort processes with the same parent by PID instead of by name:

5. Show User/Owner of Processes (-u)
To display the owner of each process:

6. Highlight Current Process (-h)
To highlight the current process and its ancestors:

7. Show Process Group IDs (-g)
To display process group IDs:

Advanced Usages of pstree Command
1. Display Process Tree for a Specific User
To show all process trees rooted at processes owned by a specific user:

Replace `username` with the actual username you want to investigate.
2. Display Version Information
To check the version of `pstree` installed on your system:

Output:
