Linux shell编程学习条记61: pstree 下令——表现进程树

[复制链接]
发表于 2026-2-26 03:55:03 | 显示全部楼层 |阅读模式

 
0 媒介


Linux shell编程学习条记59: ps 获取体系进程信息,类似于Windows体系中的tasklist 下令
https://blog.csdn.net/Purpleendurer/article/details/139696466?spm=1001.2014.3001.5501


中我们研究了ps下令。在Linux中,通过ps下令,我们可以查察体系中运行的进程信息,包罗进程的ID、父进程ID、CPU和内存占用等信息。不外ps下令表现的进程信息中,进程间的父子关系还不敷直观。
Linux还提供了pstree下令,可以以树的情势直观地表现进程间的关系。
1 pstree 下令 的功能、格式和选项分析

我们先看一下pstree下令的资助信息。
pstree下令 不支持 --help选项。
  1. [purpleendurer @ bash ~] pstree --help
  2. pstree: 未知的选项 `--help'
  3. Usage: pstree [ -a ] [ -c ] [ -h | -H PID ] [ -l ] [ -n ] [ -p ] [ -g ] [ -u ]
  4.               [ -A | -G | -U ] [ PID | USER ]
  5.        pstree -V
  6. Display a tree of processes.
  7.   -a, --arguments     show command line arguments
  8.   -A, --ascii         use ASCII line drawing characters
  9.   -c, --compact       don't compact identical subtrees
  10.   -h, --highlight-all highlight current process and its ancestors
  11.   -H PID,
  12.   --highlight-pid=PID highlight this process and its ancestors
  13.   -g, --show-pgids    show process group ids; implies -c
  14.   -G, --vt100         use VT100 line drawing characters
  15.   -l, --long          don't truncate long lines
  16.   -n, --numeric-sort  sort output by PID
  17.   -N type,
  18.   --ns-sort=type      sort by namespace type (ipc, mnt, net, pid, user, uts)
  19.   -p, --show-pids     show PIDs; implies -c
  20.   -s, --show-parents  show parents of the selected process
  21.   -S, --ns-changes    show namespace transitions
  22.   -u, --uid-changes   show uid transitions
  23.   -U, --unicode       use UTF-8 (Unicode) line drawing characters
  24.   -V, --version       display version information
  25.   -Z     show         SELinux security contexts
  26.   PID    start at this PID; default is 1 (init)
  27.   USER   show only trees rooted at processes of this user
  28. [purpleendurer @ bash ~]
复制代码
 
1.1 pstree 下令 的功能

表现进程树(Display a tree of processes)。
1.2  pstree下令的格式

   ps [选项]   [PID |  USER]
  或
    ps -V
  1.3 pstree下令的选项

选项功能 -a
--arguments
表现进程对应下令行有参数,如果是被影象体置换出去的进程则会加上括号 -A
--ascii
使用ASCII码线条绘制字符 -c
--compact
如果有重复的进程名, 则分开列出(预设值是会在前面加上 *) -h
--highlight-all
突出表现当前流程及其先人 -H PID
--highlight-pid=PID
突出表现指定PID的过程及其先人 -g
--show-pgids
表现进程组 ID;隐含 -c -G
--vt100
使用 VT100 线条绘制字符 -l
--long
不要截断长线 -n
--numeric-sort
按 PID 对输出举行排序 -N type
--ns-sort=type
按定名空间范例排序(IPC、MNT、NET、PID、USER、UTS) -p
--show-pids
表现 PID;隐含 -c -s
--show-parents
表现所选进程的父进程 -S
--ns-changes
表现定名空间转换 -u
--uid-changes
表现 UID 转换 -U
--unicode
使用 UTF-8 (Unicode) 线条绘制字符 -V
--version
表现版本信息1.3 pstree下令的参数

参数分析PID从指定的PID开始,默认值为1USER以指定用户表现进程树2 pstree下令实列

2.1 pstree | more 分页表现进程树

  1. [purpleendurer @ bash ~] pstree | more
  2. systemd-+-ETSMJBZGN0---3*[{ETSMJBZGN0}]
  3.         |-ETSMJBZGN10
  4.         |-ETSMJBZUI1-+-29*[QOperationLogTh]
  5.         |            |-11*[QRemoveLabelThr]
  6.         |            |-{QFunctionPipe}
  7.         |            |-{QKeepSessionThr}
  8.         |            |-2*[{QOperationLogTh}]
  9.         |            |-{QPluginOutPipe}
  10.         |            |-{QProcessManager}
  11.         |            |-{QRightMenuPipe}
  12.         |            `-{QSLPluginPipe}
  13.         |-ETSMJBZUI11---8*[{ThreadServer}]
  14.         |-ETSMJBZUI13---sleep
  15.         |-ETSMJBZWJTX0---{ETSMJBZWJTX0}
  16.         |-2*[ETSMJBZWJTX1]
  17.         |-FoxitOfficeSuit---FoxitOfficeSuit-+-FoxitUpgrade
  18.         |                                   `-3*[{FoxitOfficeSuit}]
  19.         |-NetworkManager-+-dhclient
  20.         |                |-dnsmasq
  21.         |                |-{gdbus}
  22.         |                `-{gmain}
  23.         |-PNXClientHost.o---PNXClientHost.o
  24.         |-SuwellUpdateSer
  25.         |-WLHXXYCGN701
  26.         |-WLHXXYCGN702---{WLHXXYCGN702}
  27.         |-WLHXXYCGN802
  28.         |-accounts-daemon-+-{gdbus}
  29.         |                 `-{gmain}
  30.         |-acpid
  31.         |-activation-daem
  32.         |-2*[agetty]
  33.         |-aptd---{gmain}
  34.         |-auditd---{auditd}
  35.         |-avahi-daemon---avahi-daemon
  36.         |-backup-daemon---{QDBusConnection}
  37.         |-biometric-authe-+-2*[{biometric-authe}]
  38.         |                 |-{gdbus}
  39.         |                 `-{gmain}
  40.         |-2*[cat]
  41. --更多--
复制代码
 

 

 2.2 pstree -apn | more :用ASCII码线条绘制字符表现在运行的进程树,包罗下令参数和PID

  1. [purpleendurer @ bash ~] pstree -apn | more
  2. systemd,1 splash
  3.   |-sqaxsafeforcnos,367 --minishow
  4.   |   |-{QXcbEventReader},371
  5.   |   |-{llvmpipe-0},386
  6.   |   |-{llvmpipe-1},387
  7.   |   |-{llvmpipe-2},388
  8.   |   |-{llvmpipe-3},389
  9.   |   |-{QDBusConnection},390
  10.   |   |-{gmain},415
  11.   |   |-{gdbus},416
  12.   |   |-{CASocketThread},428
  13.   |   |-{sqaxsafeforcnos},432
  14.   |   |-{sqaxsafeforcnos},433
  15.   |   |-{sqaxsafeforcnos},434
  16.   |   |-{sqaxsafeforcnos},435
  17.   |   |-{sqaxsafeforcnos},436
  18.   |   |-{sqaxsafeforcnos},437
  19.   |   |-{sqaxsafeforcnos},438
  20.   |   |-{sqaxsafeforcnos},439
  21.   |   |-{sqaxsafeforcnos},497
  22.   |   |-{sqaxsafeforcnos},498
  23.   |   |-{sqaxsafeforcnos},499
  24.   |   |-{sqaxsafeforcnos},500
  25.   |   |-{sqaxsafeforcnos},501
  26.   |   |-{sqaxsafeforcnos},502
  27.   |   |-{sqaxsafeforcnos},503
  28.   |   |-{sqaxsafeforcnos},504
  29.   |   |-{sqaxsafeforcnos},506
  30.   |   |-{sqaxsafeforcnos},507
  31.   |   |-{sqaxsafeforcnos},508
  32.   |   |-{sqaxsafeforcnos},509
  33.   |   |-{sqaxsafeforcnos},510
  34.   |   |-{sqaxsafeforcnos},511
  35.   |   |-{sqaxsafeforcnos},512
  36.   |   |-{sqaxsafeforcnos},516
  37.   |   |-{XTableThread},520
  38.   |   |-{SpeedCtrl},522
  39.   |   |-{QThread},524
  40.   |   `-{CpuMemState},525
  41.   |-systemd-udevd,420
  42.   |-haveged,423 --Foreground --verbose=1 -w 1024
  43.   |-systemd-journal,425
  44.   |-qaxtray_5,518 --reboot
  45.   |   |-{QXcbEventReader},523
  46.   |   |-{llvmpipe-0},526
  47.   |   |-{llvmpipe-1},527
  48.   |   |-{llvmpipe-2},528
  49.   |   |-{llvmpipe-3},529
  50.   |   |-{QDBusConnection},530
  51.   |   |-{gmain},531
  52.   |   |-{gdbus},532
  53.   |   |-{qaxtray_5},581
  54.   |   |-{qaxtray_5},582
  55.   |   |-{qaxtray_5},583
  56.   |   |-{qaxtray_5},584
  57.   |   |-{QThread},591
  58. --更多--
复制代码

3.3  pstree -p 795:表现以PID为795的进程为根的进程树,包罗PID

  1. [purpleendurer @ bash ~] pstree -p 795
  2. accounts-daemon(795)─┬─{gdbus}(834)
  3.                      └─{gmain}(824)
  4. [purpleendurer @ bash ~]
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!qidao123.com:ToB企服之家,中国第一个企服评测及软件市场,开放入驻,技术点评得现金

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表