Mac可以通过命令pstree
显示进程树。
安装:
$ brew install pstree
帮助文档:
$ pstree --help
pstree: illegal option -- -
pstree $Revision: 2.39 $ by Fred Hucht (C) 1993-2015
EMail: fred AT thp.uni-due.de
Usage: pstree [-f file] [-g n] [-l n] [-u user] [-U] [-s string] [-p pid] [-w] [pid ...]
-f file read input from <file> (- is stdin) instead of running
"ps -axwwo user,pid,ppid,pgid,command"
-g n use graphics chars for tree. n=1: IBM-850, n=2: VT100, n=3: UTF-8
-l n print tree to n level deep
-u user show only branches containing processes of <user>
-U don't show branches containing only root processes
-s string show only branches containing process with <string> in commandline
-p pid show only branches containing process <pid>
-w wide output, not truncated to window width
pid ... process ids to start from, default is 1 (probably init)
Process group leaders are marked with '='.
示例:
通过进程名显示进程树:
$ pstree -s terraform
-+= 00001 root /sbin/launchd
\-+= 50669 larry /Users/larry/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/213.5744.223/IntelliJ ID
\-+= 51403 larry /bin/bash --rcfile /Users/larry/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/213
\-+= 55301 larry terraform apply
\--- 55302 larry /Users/larry/Software/terraform/terraform apply
通过进程ID显示进程树,父进程和子进程都会显示:
$ pstree -p 55301
-+= 00001 root /sbin/launchd
\-+= 50669 larry /Users/larry/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/213.5744.223/IntelliJ ID
\-+= 51403 larry /bin/bash --rcfile /Users/larry/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/213
\-+= 55301 larry terraform apply
\--- 55302 larry /Users/larry/Software/terraform/terraform apply
通过进程ID显示,但只显示它和子进程:
$ pstree 55301
-+= 55301 larry terraform apply
\--- 55302 larry /Users/larry/Software/terraform/terraform apply