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选项。
- [purpleendurer @ bash ~] pstree --help
- pstree: 未知的选项 `--help'
- Usage: pstree [ -a ] [ -c ] [ -h | -H PID ] [ -l ] [ -n ] [ -p ] [ -g ] [ -u ]
- [ -A | -G | -U ] [ PID | USER ]
- pstree -V
- Display a tree of processes.
- -a, --arguments show command line arguments
- -A, --ascii use ASCII line drawing characters
- -c, --compact don't compact identical subtrees
- -h, --highlight-all highlight current process and its ancestors
- -H PID,
- --highlight-pid=PID highlight this process and its ancestors
- -g, --show-pgids show process group ids; implies -c
- -G, --vt100 use VT100 line drawing characters
- -l, --long don't truncate long lines
- -n, --numeric-sort sort output by PID
- -N type,
- --ns-sort=type sort by namespace type (ipc, mnt, net, pid, user, uts)
- -p, --show-pids show PIDs; implies -c
- -s, --show-parents show parents of the selected process
- -S, --ns-changes show namespace transitions
- -u, --uid-changes show uid transitions
- -U, --unicode use UTF-8 (Unicode) line drawing characters
- -V, --version display version information
- -Z show SELinux security contexts
- PID start at this PID; default is 1 (init)
- USER show only trees rooted at processes of this user
- [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 分页表现进程树
- [purpleendurer @ bash ~] pstree | more
- systemd-+-ETSMJBZGN0---3*[{ETSMJBZGN0}]
- |-ETSMJBZGN10
- |-ETSMJBZUI1-+-29*[QOperationLogTh]
- | |-11*[QRemoveLabelThr]
- | |-{QFunctionPipe}
- | |-{QKeepSessionThr}
- | |-2*[{QOperationLogTh}]
- | |-{QPluginOutPipe}
- | |-{QProcessManager}
- | |-{QRightMenuPipe}
- | `-{QSLPluginPipe}
- |-ETSMJBZUI11---8*[{ThreadServer}]
- |-ETSMJBZUI13---sleep
- |-ETSMJBZWJTX0---{ETSMJBZWJTX0}
- |-2*[ETSMJBZWJTX1]
- |-FoxitOfficeSuit---FoxitOfficeSuit-+-FoxitUpgrade
- | `-3*[{FoxitOfficeSuit}]
- |-NetworkManager-+-dhclient
- | |-dnsmasq
- | |-{gdbus}
- | `-{gmain}
- |-PNXClientHost.o---PNXClientHost.o
- |-SuwellUpdateSer
- |-WLHXXYCGN701
- |-WLHXXYCGN702---{WLHXXYCGN702}
- |-WLHXXYCGN802
- |-accounts-daemon-+-{gdbus}
- | `-{gmain}
- |-acpid
- |-activation-daem
- |-2*[agetty]
- |-aptd---{gmain}
- |-auditd---{auditd}
- |-avahi-daemon---avahi-daemon
- |-backup-daemon---{QDBusConnection}
- |-biometric-authe-+-2*[{biometric-authe}]
- | |-{gdbus}
- | `-{gmain}
- |-2*[cat]
- --更多--
复制代码
2.2 pstree -apn | more :用ASCII码线条绘制字符表现在运行的进程树,包罗下令参数和PID
- [purpleendurer @ bash ~] pstree -apn | more
- systemd,1 splash
- |-sqaxsafeforcnos,367 --minishow
- | |-{QXcbEventReader},371
- | |-{llvmpipe-0},386
- | |-{llvmpipe-1},387
- | |-{llvmpipe-2},388
- | |-{llvmpipe-3},389
- | |-{QDBusConnection},390
- | |-{gmain},415
- | |-{gdbus},416
- | |-{CASocketThread},428
- | |-{sqaxsafeforcnos},432
- | |-{sqaxsafeforcnos},433
- | |-{sqaxsafeforcnos},434
- | |-{sqaxsafeforcnos},435
- | |-{sqaxsafeforcnos},436
- | |-{sqaxsafeforcnos},437
- | |-{sqaxsafeforcnos},438
- | |-{sqaxsafeforcnos},439
- | |-{sqaxsafeforcnos},497
- | |-{sqaxsafeforcnos},498
- | |-{sqaxsafeforcnos},499
- | |-{sqaxsafeforcnos},500
- | |-{sqaxsafeforcnos},501
- | |-{sqaxsafeforcnos},502
- | |-{sqaxsafeforcnos},503
- | |-{sqaxsafeforcnos},504
- | |-{sqaxsafeforcnos},506
- | |-{sqaxsafeforcnos},507
- | |-{sqaxsafeforcnos},508
- | |-{sqaxsafeforcnos},509
- | |-{sqaxsafeforcnos},510
- | |-{sqaxsafeforcnos},511
- | |-{sqaxsafeforcnos},512
- | |-{sqaxsafeforcnos},516
- | |-{XTableThread},520
- | |-{SpeedCtrl},522
- | |-{QThread},524
- | `-{CpuMemState},525
- |-systemd-udevd,420
- |-haveged,423 --Foreground --verbose=1 -w 1024
- |-systemd-journal,425
- |-qaxtray_5,518 --reboot
- | |-{QXcbEventReader},523
- | |-{llvmpipe-0},526
- | |-{llvmpipe-1},527
- | |-{llvmpipe-2},528
- | |-{llvmpipe-3},529
- | |-{QDBusConnection},530
- | |-{gmain},531
- | |-{gdbus},532
- | |-{qaxtray_5},581
- | |-{qaxtray_5},582
- | |-{qaxtray_5},583
- | |-{qaxtray_5},584
- | |-{QThread},591
- --更多--
复制代码
3.3 pstree -p 795:表现以PID为795的进程为根的进程树,包罗PID
- [purpleendurer @ bash ~] pstree -p 795
- accounts-daemon(795)─┬─{gdbus}(834)
- └─{gmain}(824)
- [purpleendurer @ bash ~]
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!qidao123.com:ToB企服之家,中国第一个企服评测及软件市场,开放入驻,技术点评得现金 |