Linux命令之pstree
1.pstree介绍
linux命令pstree(全称:display a tree of processes)命令将进程以树状图显示
2.pstree用法
pstree用法
pstree [参数]
参数 | 说明 |
-p | 显示进程的PID |
-u | 显示进程的user |
-V | 显示pstree的版本信息 |
-p pid | 显示进程号为pid的进程信息 |
-u user | 显示用户名为user的进程信息 |
3.实例
3.1.显示进程的PID
命令:
pstree -p
[root@rhel77 yum.repos.d]# pstree -p
systemd(1)─┬─NetworkManager(883)─┬─dhclient(1613)│ ├─{NetworkManager}(898)│ └─{NetworkManager}(902)├─VGAuthService(876)├─auditd(848)───{auditd}(849)├─crond(885)├─dbus-daemon(879)├─httpd(1148)─┬─httpd(1200)│ ├─httpd(1201)│ ├─httpd(1203)│ ├─httpd(1208)│ └─httpd(1210)├─irqbalance(873)├─login(895)───bash(1391)├─lvmetad(601)├─mysqld(1185)─┬─{mysqld}(1326)│ ├─{mysqld}(1347)│ ├─{mysqld}(1348)│ ├─{mysqld}(1349)│ ├─{mysqld}(1350)│ ├─{mysqld}(1351)│ ├─{mysqld}(1352)│ ├─{mysqld}(1353)│ ├─{mysqld}(1354)│ ├─{mysqld}(1355)│ ├─{mysqld}(1356)│ ├─{mysqld}(1357)│ ├─{mysqld}(1369)│ ├─{mysqld}(1370)│ ├─{mysqld}(1371)│ ├─{mysqld}(1372)│ ├─{mysqld}(1373)│ ├─{mysqld}(1374)│ ├─{mysqld}(1375)│ ├─{mysqld}(1376)│ ├─{mysqld}(1377)│ ├─{mysqld}(1378)│ ├─{mysqld}(1379)│ ├─{mysqld}(1380)│ ├─{mysqld}(1381)│ └─{mysqld}(1382)├─polkitd(874)─┬─{polkitd}(888)│ ├─{polkitd}(890)│ ├─{polkitd}(891)│ ├─{polkitd}(892)│ ├─{polkitd}(893)│ └─{polkitd}(896)├─rhnsd(1169)├─rhsmcertd(1158)├─rsyslogd(1154)─┬─{rsyslogd}(1187)│ └─{rsyslogd}(1188)├─sshd(1152)─┬─sshd(1407)───bash(1409)───pstree(2695)│ └─sshd(1482)───bash(1484)├─systemd-journal(578)├─systemd-logind(871)├─systemd-udevd(599)├─tuned(1149)─┬─{tuned}(1363)│ ├─{tuned}(1364)│ ├─{tuned}(1366)│ └─{tuned}(1367)└─vmtoolsd(877)───{vmtoolsd}(905)
[root@rhel77 yum.repos.d]#
3.2.显示进程的user
命令:
pstree -u
[root@rhel77 yum.repos.d]# pstree -u
systemd─┬─NetworkManager─┬─dhclient│ └─2*[{NetworkManager}]├─VGAuthService├─auditd───{auditd}├─crond├─dbus-daemon(dbus)├─httpd───5*[httpd(apache)]├─irqbalance├─login───bash├─lvmetad├─mysqld(mysql)───26*[{mysqld}]├─polkitd(polkitd)───6*[{polkitd}]├─rhnsd├─rhsmcertd├─rsyslogd───2*[{rsyslogd}]├─sshd─┬─sshd───bash───pstree│ └─sshd───bash├─systemd-journal├─systemd-logind├─systemd-udevd├─tuned───4*[{tuned}]└─vmtoolsd───{vmtoolsd}
[root@rhel77 yum.repos.d]#
3.3.显示pstree的版本信息
命令:
pstree -V
[root@rhel77 yum.repos.d]# pstree -V
pstree (PSmisc) 22.20
Copyright (C) 1993-2009 Werner Almesberger and Craig SmallPSmisc comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under
the terms of the GNU General Public License.
For more information about these matters, see the files named COPYING.
[root@rhel77 yum.repos.d]#
3.4.显示进程号为1185的进程信息
命令:
pstree -p 1185
[root@rhel77 yum.repos.d]# pstree -p 1185
mysqld(1185)─┬─{mysqld}(1326)├─{mysqld}(1347)├─{mysqld}(1348)├─{mysqld}(1349)├─{mysqld}(1350)├─{mysqld}(1351)├─{mysqld}(1352)├─{mysqld}(1353)├─{mysqld}(1354)├─{mysqld}(1355)├─{mysqld}(1356)├─{mysqld}(1357)├─{mysqld}(1369)├─{mysqld}(1370)├─{mysqld}(1371)├─{mysqld}(1372)├─{mysqld}(1373)├─{mysqld}(1374)├─{mysqld}(1375)├─{mysqld}(1376)├─{mysqld}(1377)├─{mysqld}(1378)├─{mysqld}(1379)├─{mysqld}(1380)├─{mysqld}(1381)└─{mysqld}(1382)
[root@rhel77 yum.repos.d]#
3.5.显示用户名为mysql的进程信息
命令:
pstree -u mysql
[root@rhel77 yum.repos.d]# pstree -u mysql
mysqld───26*[{mysqld}]
[root@rhel77 yum.repos.d]#