进程树 pstree

进程树 pstree

pstree

ps 更直观!更好用!

Linux pstree 命令将所有行程以树状图显示,树状图将会以 pid (如果有指定) 或是以 init,systemd 这个基本行程为根 (root),如果有指定使用者 id,则树状图会只显示该使用者所拥有的行程。

ps -ef f 类似,只不过,pstree 不是将所有的进程都显示出来,ps -ef f 是,因为 -e 参数就是显示所有的进程

pstree [-a] [-c] [-h|-Hpid] [-l] [-n] [-p] [-u] [-G|-U] [pid|user]

常用参数 -a -h -u -p

简单实践:

一般我们都是在 top 命令中查看到异常进程,然后在 pstree 中运行 ps -aup <pid>

-u-p 参数的 uid 和 pid 也是追加到命令名称后面的,会跟 -a 参数显示的信息混在一起,如果你不想他们混在一起,就分开查

pstree -ah

………

可以很明显地看出,所有进程的根进程都是 systemd,pid 为 1,因为它是由 Linux 内核主动调用的一个进程。而且 systemd 正在使用(字体加粗了)

pstree -hup

………

我们还可以指定 pid,只显示这一个分支

pstree -p <pid>

我们还可以指定 uid

pstree -u <user>