The pstree tool prints a tree with the relationship between parent and child processes. If we run it without any arguments it will show the process hierarchy for all the processes currently running in the system.
If we give it one PID it will print the hierarchy beneath it:
root:/home/marc> pstree `pgrep kdeinit`
kdeinit4 ─┬─ gedit ─┬─ {dconf worker}
│ ├─ {gdbus}
│ └─ {gmain}
├─ klauncher
└─ oosplash ─┬─ soffice.bin ─┬─ {ICEConnectionWo}
│ ├─ {OfficeIPCThread}
│ ├─ {SelectionManage}
│ ├─ {gdbus}
│ ├─ {gmain}
│ └─ {rtl_cache_wsupd}
├─ {oosplash}
└─ {rtl_cache_wsupd}
If we add the “-a” flag it will show the process arguments:
root:/home/marc> pstree 23230 -a
kdeinit4 e
├─ gedit /home/marc/Documents/linux/rhcsa/rhcsa_objectives.txt
│ ├─ {dconf worker}
│ ├─ {gdbus}
│ └─ {gmain}
├─ klauncher e
└─ oosplash –writer /home/marc/Documents/linux/rhcsa/rhcsa-booting-process.odt
├─ soffice.bin –writer /home/marc/Documents/linux/rhcsa/rhcsa-booting-process.odt –splashpipe=5
│ ├─ {ICEConnectionWo}
│ ├─ {OfficeIPCThread}
│ ├─ {SelectionManage}
│ ├─ {gdbus}
│ ├─ {gmain}
│ └─ {rtl_cache_wsupd}
├─ {oosplash}
└─ {rtl_cache_wsupd}
With the “-p” it will show the PIDs and with the “-g” the GIDs:
root:/home/marc> pstree 23230 -pg
kdeinit4(23230,23230) ─┬─ gedit(18035,23230) ─┬─ {dconf worker}(18037,23230)
│ ├─ {gdbus}(18036,23230)
│ └─ {gmain}(18038,23230)
├─ klauncher(23232,23230)
└─ oosplash(18563,23230) ─┬─ soffice.bin(18576,23230) ─┬─ {ICEConnectionWo}(18581,23230)
│ ├─ {OfficeIPCThread}(18579,23230)
│ ├─ {SelectionManage}(18582,23230)
│ ├─ {gdbus}(18580,23230)
│ ├─ {gmain}(18587,23230)
│ └─ {rtl_cache_wsupd}(18577,23230)
├─ {oosplash}(18575,23230)
└─ {rtl_cache_wsupd}(18571,23230)
Other flags we can use are:
h → highlights the current processes
n → sorts the process numerically by PID rather than alphabetically
s → shows also the parent process of the given PID
Z → shows SELinux contexts