pstree Command in Linux with Examples
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.
Syntax
pstree [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 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:
-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 option3. Disable Compaction of Identical Subtrees (-c)
By default, `pstree` compacts identical branches. Use the `-c` option to expand all subtrees:
Disable Compaction of Identical Subtrees4. Sort Processes by PID (-n)
To sort processes with the same parent by PID instead of by name:
Sort Processes by PID5. Show User/Owner of Processes (-u)
To display the owner of each process:
Show User/Owner of Processes6. Highlight Current Process (-h)
To highlight the current process and its ancestors:
Highlight Current Process7. Show Process Group IDs (-g)
To display process group IDs:
Show Process Group IDsAdvanced 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:
Display Process Tree for a Specific UserReplace `username` with the actual username you want to investigate.
2. Display Version Information
To check the version of `pstree` installed on your system:
Display Version InformationOutput:
OutputConclusion
The 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.
Similar Reads
read command in Linux with Examples read command in the Linux system is used to read from a file descriptor. This command reads up the total number of bytes from the specified file descriptor into the buffer. If the number or count is zero, this command may detect errors. But on success, it returns the number of bytes read. Zero indic
3 min read
nproc Command in Linux with Examples nproc It is a simple Unix command which is used to print the number of processing units available in the system or to the current process. This command could be used in system diagnostics and related purposes. It is part of GNU Core utils, so it comes pre-installed with all modern Linux operating sy
3 min read
rcp Command in Linux with examples When working in a Linux environment, there often comes a time when you need to transfer files from one computer to another. While more secure options like scp or rsync exist, the rcp (Remote Copy Protocol) command offers a simple and efficient way to copy files between systems, especially for beginn
5 min read
Linux stress command With Examples The 'stress' command is a robust command-line tool available on Linux-based operating systems. It's designed to assess the performance and reliability of hardware and software by simulating a high-load environment. Here we will cover everything from installation to practical usage.Introduction to "s
5 min read
users command in Linux with Examples users command in Linux system is used to show the user names of users currently logged in to the current host. It will display who is currently logged in according to FILE. If the FILE is not specified, use "/var/run/utmp". "/var/log/wtmp" as FILE is common. Syntaxusers [OPTION]... [FILE]where,OPTIO
2 min read
pmap command in Linux with Examples The pmap command in Linux is a powerful utility used to display the memory map of a process. A memory map provides insight into how memory is allocated and distributed within a running process. This can be incredibly useful for developers and system administrators when debugging memory issues, optim
3 min read
username Command in Linux With Examples Linux as an operating system holds the capabilities of handling multiple users each with a username and a display name (Full Name). So it is important to keep a check on the users and their related information in order to maintain the integrity and security of the system. Whenever a user is added it
4 min read
printf command in Linux with Examples The 'printf' command in Linux is a versatile tool used to display formatted text, numbers, or other data types directly in the terminal. Like the 'printf' function in programming languages like C, the Linux printf command allows users to format output with great precision, making it ideal for script
4 min read
script command in Linux with Examples The 'script' command in Linux is a versatile tool that allows you to record all terminal activities, including inputs and outputs, making it a valuable resource for developers, system administrators, educators, and anyone who needs to document terminal sessions. This command captures everything disp
5 min read
lshw command in Linux with Examples The 'lshw' (List Hardware) command in Linux/Unix is a powerful tool for extracting detailed information about the system's hardware configuration. This tool retrieves data from files in the '/proc' directory and is capable of reporting on a wide array of components, including memory configuration, C
3 min read