其他分享
首页 > 其他分享> > pstree命令详解

pstree命令详解

作者:互联网

 

pstree命令是用于查看进程树之间的关系,即哪个进程是父进程,哪个是子进程,可以清楚的看出来是谁创建了谁
#pstree
几个重要的参数:
-A: 各进程树之间的连接以ASCII码字符来连接
-U:各进程树之间的连接以utf8字符来连接,某些终端可能会有错误
-p:同时列出每个进程的PID
-u: 同时列出每个进程的所属账号名称:
例子:
#pstree  -up

systemd(1)-+-agetty(2021)           |-agetty(2022)           |-bash(23254,ffy)           |-chronyd(1180,chrony)           |-crond(1277)---crond(25734)---sogou-agent(25736)---sleep(25759)           |-dbus-daemon(1123,dbus)                      |-python(25707,dlj)-+-python(25778)-+-{python}(25781)           |                   |               |-{python}(25783)           |                   |               |-{python}(25784)           |                   |               |-{python}(27547)           |                   |               `-{python}(27548)           |                   |-python(25779)-+-{python}(25785)           |                   |               |-{python}(25786)           |                   |               `-{python}(25788)           |                   |-python(25780)-+-{python}(27549)           |                   |               |-{python}(27550)           |                   |               |-{python}(27551)           |                   |               |-{python}(27552)           |                   |               |-{python}(27553)           |                   |               |-{python}(27554)           |                   |               `-{python}(27555)           |                   |-python(25782)-+-{python}(29319)           |                   |               |-{python}(29320)           |                   |               |-{python}(29321)           |                   |               |-{python}(29322)           |                   |               |-{python}(29323)           |                   |               |-{python}(29324)           |                   |               `-{python}(29325)           |                   `-python(25787)          


可以看到所有的进程都是依附在systemd这个进程下面,它的进程PID是1,因为它是由Linux内核主动调用的一个进程。

可以从中看出来进程所属的用户为dlj,每个进程的pid
而且,25707这个进程有5个子进程,分别为25778,25779,25780,25782,25787
25778这个进程也有几个子线程,分别为,25781,25783,25784,27547,27548
---------------------
作者:田野上的希望
来源:CSDN
原文:https://blog.csdn.net/u011734144/article/details/77567398
版权声明:本文为博主原创文章,转载请附上博文链接!  

 

pstree命令以树状图显示进程间的关系(display a tree of processes)。ps命令可以显示当前正在运行的那些进程的信息,但是对于它们之间的关系却显示得不够清晰。在Linux系统中,系统调用fork可以创建子进程,通过子shell也可以创建子进程,Linux系统中进程之间的关系天生就是一棵树,树的根就是进程PID为1的init进程。
以树状图只显示进程的名字,且相同进程合并显示:
格式:pstree
[root@localhost ~]# pstree
init─┬─2*[.sshd───{.sshd}]
     ├─NetworkManager
     ├─abrtd
     ├─acpid
     ├─atd
     ├─auditd───{auditd}
     ├─automount───4*[{automount}]
     ├─bonobo-activati───{bonobo-activat}
     ├─certmonger
     ├─console-kit-dae───63*[{console-kit-da}]
     ├─crond
     ├─cupsd
     ├─2*[dbus-daemon]
     ├─dbus-launch
     ├─devkit-power-da
     ├─2*[f62───8*[{f62}]]
     ├─gconfd-2
     ├─gdm-binary─┬─gdm-simple-slav─┬─Xorg
     │            │                 ├─gdm-session-wor
     │            │                 ├─gnome-session─┬─at-spi-registry
     │            │                 │               ├─gdm-simple-gree
     │            │                 │               ├─gnome-power-man
     │            │                 │               ├─metacity
     │            │                 │               ├─polkit-gnome-au
     │            │                 │               └─{gnome-session}
     │            │                 └─{gdm-simple-sla}
     │            └─{gdm-binary}
     ├─gnome-settings-───{gnome-settings}
     ├─gvfsd
     ├─hald─┬─hald-runner─┬─hald-addon-acpi
     │      │             └─hald-addon-inpu
     │      └─{hald}
     ├─irqbalance
     ├─memcached───5*[{memcached}]
     ├─5*[mingetty]
     ├─modem-manager
     ├─mysqld_safe───mysqld───22*[{mysqld}]
     ├─nginx───4*[nginx]
     ├─pcscd───{pcscd}
     ├─php-fpm───4*[php-fpm]
     ├─polkitd
     ├─portreserve
     ├─pulseaudio───3*[{pulseaudio}]
     ├─redis-server───2*[{redis-server}]
     ├─rpc.statd
     ├─rpcbind
     ├─rsyslogd───3*[{rsyslogd}]
     ├─rtkit-daemon───2*[{rtkit-daemon}]
     ├─2*[sendmail]
     ├─sshd───sshd───bash───pstree
     ├─svnserve
     ├─szovajrhbf───3*[{szovajrhbf}]
     ├─udevd───2*[udevd]
     ├─5*[wjbdddweva]
     ├─wpa_supplicant
     └─xinetd
[root@localhost ~]#
以树状图显示进程同时还显示PID:
格式:pstree -p
以树状图显示进程PID为<pid>的进程以及子孙进程,如果有-p参数则同时显示每个进程的PID:
格式:pstree [-p] <pid>
[root@localhost ~]# pstree 2500
mysqld_safe───mysqld───22*[{mysqld}]
[root@localhost ~]# pstree -p 2500
mysqld_safe(2500)───mysqld(2972)─┬─{mysqld}(3062)
                                 ├─{mysqld}(3063)
                                 ├─{mysqld}(3064)
                                 ├─{mysqld}(3065)
                                 ├─{mysqld}(3066)
                                 ├─{mysqld}(3067)
                                 ├─{mysqld}(3068)
                                 ├─{mysqld}(3069)
                                 ├─{mysqld}(3070)
                                 ├─{mysqld}(3071)
                                 ├─{mysqld}(3082)
                                 ├─{mysqld}(3083)
                                 ├─{mysqld}(3084)
                                 ├─{mysqld}(3085)
                                 ├─{mysqld}(3173)
                                 ├─{mysqld}(10962)
                                 ├─{mysqld}(13819)
                                 ├─{mysqld}(28967)
                                 ├─{mysqld}(14425)
                                 ├─{mysqld}(20321)
                                 ├─{mysqld}(20429)
                                 └─{mysqld}(20755)
[root@localhost ~]#
以树状图显示进程,相同名称的进程不合并显示,并且会显示命令行参数,如果有-p参数则同时显示每个进程的PID。
格式:pstree -a
注:因为pstree输出的信息可能比较多,所以最好与more/less配合使用,使用上下箭头查看,按q退出。
[root@localhost ~]# pstree -p | less

标签:python,PID,gdm,命令,详解,mysqld,进程,pstree
来源: https://blog.51cto.com/u_15169172/2710883