温馨提示×

怎么查看debian进程树

小樊
41
2026-09-13 17:57:42
栏目: 智能运维

在 Debian(以及大多数 Linux 发行版)中,查看进程树(以树状结构显示进程及其父子关系)有多种方式。下面按常用程度给你介绍几种方法。


一、最推荐:pstree

安装(一般已自带)

which 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 / htop

top(不直观)

top

top 默认不是树状,不太适合看进程树

htop(强烈推荐)

sudo apt install htop
htop
  • F5 切换为树视图
  • 可上下移动、杀死进程

四、 systemd 系统(Debian 8+)

查看 systemd 服务进程树

systemd-cgls

查看某个服务的进程

systemctl status ssh

五、图形化(可选)

  • gnome-system-monitor
  • ksysguard

总结推荐

需求 推荐命令
快速看进程树 pstree -p
交互式查看 htop(F5)
脚本/服务器 ps -ejH
systemd 分析 systemd-cgls

如果你有具体场景(比如:查某个进程卡死、查僵尸进程、查某个服务的子进程),可以告诉我,我可以给你更精确的命令。

0