在 Debian(以及大多数 Linux 发行版)中,查看进程树(以树状结构显示进程及其父子关系)有多种方式。下面按常用程度给你介绍几种方法。
pstreewhich pstree
# 如果没有
sudo apt install pstree
pstree
pstree -p # 显示 PID
pstree -a # 显示命令行参数
pstree -u # 显示用户
pstree -p <PID> # 查看某个进程的树
pstree <用户名> # 只显示某用户的进程
示例:
pstree -p | less
ps(系统自带)ps -ejH
或
ps -ef --forest
ps -o pid,ppid,cmd --forest
top / htoptop
top 默认不是树状,不太适合看进程树
sudo apt install htop
htop
F5 切换为树视图systemd-cgls
systemctl status ssh
gnome-system-monitorksysguard| 需求 | 推荐命令 |
|---|---|
| 快速看进程树 | pstree -p |
| 交互式查看 | htop(F5) |
| 脚本/服务器 | ps -ejH |
| systemd 分析 | systemd-cgls |
如果你有具体场景(比如:查某个进程卡死、查僵尸进程、查某个服务的子进程),可以告诉我,我可以给你更精确的命令。