在 Debian(以及大多数 Linux 发行版)中,查看进程树(以树状结构显示进程及其父子关系)有几种常用方法:
pstree(最直观)pstree
常用选项:
pstree -p # 显示 PID
pstree -u # 显示进程所属用户
pstree -a # 显示完整命令行
pstree 用户名 # 查看指定用户的进程树
示例:
pstree -p
ps 命令ps -ejH
或
ps -axjf
ps -ef --forest
(--forest 会以树状 ASCII 显示)
top / htoptop
按 V(大写)可切换树状视图(部分版本支持)
sudo apt install htop
htop
进入后按 F5 即可查看进程树。
pstree -p <PID>
或
ps -o pid,ppid,cmd --forest -g <PGID>
pstree -phtop + F5ps -ef --forest如果你是想排查某个服务(如 nginx、docker、systemd)的进程关系,也可以告诉我具体场景。