当前位置:   article > 正文

Linux shell编程学习笔记61: pstree 命令——显示进程树

Linux shell编程学习笔记61: pstree 命令——显示进程树

 

0 前言

Linux shell编程学习笔记59: ps 获取系统进程信息,类似于Windows系统中的tasklist 命令icon-default.png?t=N7T8https://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开始,默认值为1
USER以指定用户显示进程树

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 ~]

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号