Linux Pstree Command Tutorial

53

The best way to display the running process in a system is to display them as a tree hierarchy. In a Linux system, “pstree” helps visualize processes hierarchy which is a less complex way to display running processes.

The “pstree” command is one of the Linux commands that merge branches through square brackets and display the process as a tree. The root of the tree could be “init” or “pid”.

How to Use Pstree Commands in Linux

Type “pstree” command in terminal to display the hierarchy tree of all running process:

In the output, it displays the hierarchy tree structure in which systemd is the parent/root process of all the system process as it starts first when the system is booted.

Here are few examples to show the working of the “pstree” command in the Linux system:

You won’t see command-line arguments in output by default, so, to display it in the terminal, use the given command:

Linux Pstree Command Tutorial 1617239231 651 Linux Pstree Command Tutorial

When you use the “-p” with “pstree” command in the terminal, it will display PIDS in output as a decimal number within parenthesis.

Linux Pstree Command Tutorial 1617239232 345 Linux Pstree Command Tutorial

The “-c” option is used to extend “pstree” as it packed down subtrees and to display identical subtrees use:

Linux Pstree Command Tutorial 1617239232 499 Linux Pstree Command Tutorial

The “-n” option in “pstree” helps to sort process in numeric order:

Linux Pstree Command Tutorial 1617239233 281 Linux Pstree Command Tutorial

To display the user of the process, use the “-u” option with “pstree” in the terminal.

Linux Pstree Command Tutorial 1617239234 436 Linux Pstree Command Tutorial

The “-h” option in “pstree” allows to highlight the current process with its ancestors:

Linux Pstree Command Tutorial 1617239235 469 Linux Pstree Command Tutorial

To print IDs of process groups in the terminal, use “-g”:

Linux Pstree Command Tutorial 1617239235 249 Linux Pstree Command Tutorial

To get detailed information about the “pstree” version, type the “-V” command:

Linux Pstree Command Tutorial 1617239236 490 Linux Pstree Command Tutorial

Conclusion

The pstree command in Linux is used to display the running process of a system in a tree hierarchy. It makes an interesting way to merge branches and visualize them. Through this tutorial, we have learned that how to use “pstree” commands with examples.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More