How to display process hierarchies with pstree in Linux

Pstree is a nice tool for listing process hierarchies. All the processes in the system can be displayed also by the ps command, but in some cases you may need to get a hierarchical process list.

Used without any arguments, pstree displays all the processes starting with the init process, in a tree.

$ pstree | less

How to display the process tree starting from a certain process:

Syntax: pstree PID

I will grab gnome-session’s PID and display all the processes started by gnome-session, as a tree:

$ pgrep gnome-session

$ pstree 1460

How to display a user’s processes:

Syntax:pstree username

This lists all the processes belonging to the user razvan, in a tree:

$ pstree razvan
│           └─vim

How to display also the process PIDs in the process tree:

Use pstree -p to display also the process’s PIDs:

$ pstree -p 402

If you need to sort the processes by the PID, not in the alphabetical order as it is by default, use pstree -np .

Tagged with: , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *




Subscribe to get the latest Linux news and how to guides directly on your e-mail!