在 Debian(及其他 Linux 发行版)中,查看进程树(以树状结构显示进程及其父子关系)有多种常用方法。下面按“推荐程度 + 使用场景”介绍。
pstreepstree
以树状结构显示所有进程。
pstree -p
每个进程后显示 PID。
pstree -p <PID>
例如:
pstree -p 1234
pstree -u
sudo apt install pstree
(Debian 一般已包含)
ps(系统自带)ps auxf
f:显示进程树结构aux:显示所有用户进程ps -ejH
或
ps axjf
top / htoptop(默认不显示树)top
按:
V # 开启树状视图
htop(强烈推荐)sudo apt install htop
htop
systemd-cgls如果你的 Debian 使用 systemd(几乎肯定是):
systemd-cgls
按 cgroup 显示进程树,适合查看服务关系。
systemctl status sshd
或
pstree -p $(pgrep -o sshd)
| 需求 | 推荐命令 |
|---|---|
| 快速看进程树 | pstree |
| 带 PID | pstree -p |
| 实时查看 | htop |
| 系统服务结构 | systemd-cgls |
| 不装软件 | ps auxf |
如果你有具体场景(比如“查看某个程序为什么有很多子进程”或“找出僵尸进程的父进程”),我可以给你更精确的命令。