Linux Commands

Linux Pstree Command Tutorial


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:

$ pstree

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:

$ pstree –a

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

$ pstree –p

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

$ pstree –c

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

$ pstree –n

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

$ pstree –u

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

$ pstree -h

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

$ pstree –g

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

$ pstree –V

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.

About the author

Syeda Wardah Batool

I am a Software Engineer Graduate and Self Motivated Linux writer. I also love to read latest Linux books. Moreover, in my free time, i love to read books on Personal development.