TIL: pstree command

pstree is a way to view the process family tree in a unix/linux system.

$ pstree
systemd─┬─ModemManager───2*[{ModemManager}]
        ├─2*[agetty]
        ├─atd
        ├─cron
        ├─dbus-daemon
        ├─gunicorn───gunicorn
        ├─haveged
        ├─networkd-dispat
        ├─nginx───nginx
        ├─polkitd───2*[{polkitd}]
        ├─postgres───6*[postgres]
        ├─rsyslogd───3*[{rsyslogd}]
        ├─sh───node─┬─node───10*[{node}]
        │           └─10*[{node}]
        ├─sshd───sshd───sshd───bash───pstree
        ├─systemd─┬─(sd-pam)
        │         └─dbus-daemon
        ├─systemd-journal
        ├─systemd-logind
        ├─systemd-network
        ├─systemd-resolve
        ├─systemd-timesyn───{systemd-timesyn}
        ├─systemd-udevd
        ├─tmux: server───2*[bash]
        ├─udisksd───4*[{udisksd}]
        ├─unattended-upgr───{unattended-upgr}
        └─upowerd───2*[{upowerd}]

There’s some notation in how the tree is displayed:

  • multiple instances of the same process are collapsed as n*[process_name]. See 2*[agetty] above.
  • curly braces are used to show threads.

You can use pstree -a -l to view the cli arguments with which the processes were launched as well. Hide threads information with -T — useful if you wanna see how the processes were launched. Although pstree is not available on Mac OS X and you might probably wanna use the more portable ps | more for that.