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
1460
$ pstree 1460
gnome-session─┬─applet.py
├─bluetooth-apple───{bluetooth-appl}
├─deja-dup-monito───2*[{deja-dup-monit}]
├─gdu-notificatio
├─gnome-fallback-───2*[{gnome-fallback}]
├─gnome-panel───2*[{gnome-panel}]
├─gnome-settings-───2*[{gnome-settings}]
|─gnome-sound-app───{gnome-sound-ap}
├─metacity───{metacity}
├─mintupdate-laun───sh───mintUpdate───{mintUpdate}
├─nautilus───2*[{nautilus}]
├─nm-applet───{nm-applet}
|─polkit-gnome-au───{polkit-gnome-a}
├─ssh-agent
├─zeitgeist-datah───{zeitgeist-data}
└─3*[{gnome-session}]
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
su───bash─┬─su───bash─┬─gnome-open───{gnome-open}
│ └─vim
└─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
rsyslogd(402)─┬─{rsyslogd}(410)
├─{rsyslogd}(414)
└─{rsyslogd}(415)
If you need to sort the processes by the PID, not in the alphabetical order as it is by default, use pstree -np .
Leave a Reply