A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
-bash: pstree: command not found #Debian apt-get install psmisc #Ubuntu apt-get install psmisc #Alpine apk add psmisc #Arch Linux pacman -S psmisc #Kali Linux apt-get install psmisc #CentOS yum install psmisc #Centos7 默认并没有安装pstree,所以会有pstree:command not found,实际上在linux平台要安装psmisc包. #Fedora dnf install psmisc #OS X brew install pstree #Raspbian apt-get install psmisc #Docker docker run cmd.cat/pstree pstree
pstree命令 以树状图的方式展现进程之间的派生关系,显示效果比较直观。
pstree [-a, --arguments] [-c, --compact]
[-h, --highlight-all, -Hpid, --highlight-pid pid] [-g] --show-pgids]
[-l, --long] [-n, --numeric-sort] [-p, --show-pids] [-s, --show-parents]
[-u, --uid-changes] [-Z, --security-context]
[-A, --ascii, -G, --vt100, -U, --unicode] [pid, user]
pstree -V, --version
-a:显示每个程序的完整指令,包含路径,参数或是常驻服务的标示; -c:不使用精简标示法; -G:使用VT100终端机的列绘图字符; -h:列出树状图时,特别标明现在执行的程序; -H<程序识别码>:此参数的效果和指定"-h"参数类似,但特别标明指定的程序; -l:采用长列格式显示树状图; -n:用程序识别码排序。预设是以程序名称来排序; -p:显示程序识别码; -u:显示用户名称; -U:使用UTF-8列绘图字符; -V:显示版本信息。
[root@Dev ~]$pstree
init─┬─auditd───{auditd}
├─24*[cat]
├─crond
├─24*[cronolog]
├─master─┬─bounce
│ ├─cleanup
│ ├─2*[local]
│ ├─pickup
│ └─qmgr
├─memcached───5*[{memcached}]
├─6*[mingetty]
├─mysqld_safe───mysqld───37*[{mysqld}]
├─nginx───8*[nginx]
├─php-fpm───35*[php-fpm]
├─4*[redis-server───2*[{redis-server}]]
├─rsyslogd───3*[{rsyslogd}]
├─salt-minion───4*[{salt-minion}]
├─sshd───sshd───bash───pstree
├─udevd───2*[udevd]
└─zabbix_agentd───5*[zabbix_agentd]
显示当前所有进程的进程号和进程id
pstree -p
显示所有进程的所有详细信息,遇到相同的进程名可以压缩显示。
pstree -a
获取 SSH 会话的 PID
pstree -p | grep ssh # |-sshd(1221)-+-sshd(2768)---bash(2770)-+-grep(2810) # | `-sshd(2807)---sshd(2808)
从上方的输出中,你可以看到 sshd 进程与分支的树形图。sshd 的主进程是 sshd(1221),另两个分支分别为 sshd(2768) 和 sshd(2807)。