进程与作业69 条

ps 进程树展示

--forest 用缩进画出父子层级:查「这个进程是谁拉起来的」「批量清理一整棵进程树」时必用。

Linux 运维命令速查系统更新于 2026-10-12
用途父子进程树查看
语法ps -ef --forest / ps -eo pid,ppid,cmd --forest
替代pstree -p

常用示例

常用示例
ps -ef --forest | head -40
ps -eo pid,ppid,stat,cmd --forest | grep -B2 -A5 nginx
ps -eo pid,ppid,cmd --forest | grep -A10 'systemd(1)' | head -20

易错点

  • --forest 依赖 PPID 排序,混入其他排序参数会破坏树形结构
  • 孤儿进程会被 init/systemd(1) 收养:树里挂到 1 号进程下的「陌生人」要重点核查

数据来源与参考

  • man 1 ps(procps-ng 手册)

相关工具

​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌