怎么查看进程之间的父子关系?

本次就说下查看进程树的两种方法。

命令1:

ps ajxf

示例:

[root@yaomm ~]# ps axjf
 PPID   PID  PGID   SID TTY      TPGID STAT   UID   TIME COMMAND
    0     2     0     0 ?           -1 S        0   0:00 [kthreadd]
    2     4     0     0 ?           -1 S<       0   0:00  \_ [kworker/0:0H]
    2     6     0     0 ?           -1 S        0   4:33  \_ [ksoftirqd/0]
    2     7     0     0 ?           -1 S        0   3:12   \_ [kworker/1:0]
    ……
    ……
    ……
    0     1     1     1 ?           -1 Ss       0   7:49 /usr/lib/systemd/systemd --switched-root --system --deserialize 22
    1   375   375   375 ?           -1 Ss       0   0:00 /usr/sbin/lvmetad -f
    1   378   378   378 ?           -1 Ss       0   0:00 /usr/lib/systemd/systemd-udevd
    1   480   480   480 ?           -1 S<sl     0   0:17 /sbin/auditd
   1872  2007  2007  2007 ?           -1 Ss       0   0:00  \_ /bin/bash /root/start_store.sh dev -Xms512m -Xmx1024m
 2007  2496  2007  2007 ?           -1 S        0   3:27      \_ tail -100f store.log
   ……
   ……

可以查看ppid(父进程号)、pid及它们之间的关系树。

参数f显示进程树。

命令2:pstree

pstree

查看结果:

[root@yaomm ~]# pstree
systemd─┬─AliYunDun───22*[{AliYunDun}]
        ├─AliYunDunUpdate───3*[{AliYunDunUpdate}]
        ├─BT-Panel───{BT-Panel}
        ├─BT-Task───6*[{BT-Task}]
        ├─CmsGoAgent.linu─┬─exe───14*[{exe}]
        │                 └─5*[{CmsGoAgent.linu}]
        ├─2*[agetty]
        ├─aliyun-service───2*[{aliyun-service}]
        ├─assist_daemon───7*[{assist_daemon}]
        ├─atd
        ├─auditd───{auditd}
        ├─crond
        ├─dbus-daemon
        ├─dhclient
        ├─dnsmasq───dnsmasq
        ├─docker-containe─┬─start_store.sh───tail
        │                 └─9*[{docker-containe}]
        ├─docker-containe─┬─start_user.sh───tail
        │                 └─9*[{docker-containe}]
        ├─docker-containe─┬─start_community───tail
        │                 └─9*[{docker-containe}]
        ├─docker-containe─┬─start_api.sh───tail
        │                 └─9*[{docker-containe}]
        ├─docker-containe─┬─start_hardwareA───tail
        │                 └─9*[{docker-containe}]
        ├─docker-containe─┬─start_fee.sh───tail
        │                 └─9*[{docker-containe}]
        ├─docker-containe─┬─start_common.sh───tail
        │                 └─9*[{docker-containe}]
        ├─docker-containe─┬─start_order.sh───tail
        │                 └─9*[{docker-containe}]
        ├─dockerd-current─┬─docker-containe───10*[{docker-containe}]
        ……
        ……

这个结果更清晰一点