pstree命令

pstree命令

1、用法

pstree命令用来显示Linux系统中的进程状态树,用ASCII字符以树状结构来显示正在启动或执行的程序间的相互关系.

NAME
       pstree - display a tree of processes

SYNOPSIS
       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

DESCRIPTION
       pstree shows running processes as a tree.  The tree is rooted at either pid or init if pid is omitted.  If a user name is
       specified, all process trees rooted at processes owned by that user are shown.

       pstree visually merges identical branches by putting them in square brackets  and  prefixing  them  with  the  repetition
       count, e.g.

           init-+-getty
                |-getty
                |-getty
                `-getty

       becomes

           init---4*[getty]

       Child threads of a process are found under the parent process and are shown with the process name in curly braces, e.g.

           icecast2---13*[{icecast2}]

       If pstree is called as pstree.x11 then it will prompt the user at the end of the line to press return and will not return
       until that has happened.  This is useful for when pstree is run in a xterminal.

       Certain kernel or mount parameters, such as the hidepid option for procfs, will hide information for some  processes.  In
       these situations pstree will attempt to build the tree without this information, showing process names as question marks.

OPTIONS
       -a     Show  command line arguments.  If the command line of a process is swapped out, that process is shown in parenthe-
              ses.  -a implicitly disables compaction for processes but not threads.

       -A     Use ASCII characters to draw the tree.

       -c     Disable compaction of identical subtrees.  By default, subtrees are compacted whenever possible.

       -G     Use VT100 line drawing characters.

       -h     Highlight the current process and its ancestors.  This is a no-op if the terminal doesn't support highlighting  or
              if neither the current process nor any of its ancestors are in the subtree being shown.

       -H     Like  -h, but highlight the specified process instead.  Unlike with -h, pstree fails when using -H if highlighting
              is not available.

       -g     Show PGIDs.  Process Group IDs are shown as decimal numbers in parentheses after each process name.  -p implicitly
              disables compaction.  If both PIDs and PGIDs are displayed then PIDs are shown first.

       -l     Display long lines.  By default, lines are truncated to the display width or 132 if output is sent to a non-tty or
              if the display width is unknown.

       -n     Sort processes with the same ancestor by PID instead of by name.  (Numeric sort.)

       -p     Show PIDs.  PIDs are shown as decimal numbers in parentheses after each process name.  -p implicitly disables com-
              paction.

       -s     Show parent processes of the specified process.

       -u     Show  uid  transitions.  Whenever the uid of a process differs from the uid of its parent, the new uid is shown in
              parentheses after the process name.

       -U     Use UTF-8 (Unicode) line drawing characters.  Under Linux 1.1-54 and above, UTF-8 mode is entered on  the  console
              with echo -e ' 33%8' and left with echo -e ' 33%@'

       -V     Display version information.

       -Z     (SELinux)  Show  security  context for each process.  This flag will only work if pstree is compilied with SELinux
              support.

FILES
       /proc  location of the proc file system

BUGS
       Some character sets may be incompatible with the VT100 characters.

SEE ALSO
       ps(1), top(1).

部分参数中文解释

  • -a  显示每个程序的完整指令,包含路径,参数或是常驻服务的标示。
  • -c  不使用精简标示法。如果有重覆的行程名, 则分开列出 (预设值是会在前面加上 *)
  • -G  使用VT100终端机的列绘图字符。
  • -h  列出树状图时,特别标明现在执行的程序。
  • -H<程序识别码>  此参数的效果和指定"-h"参数类似,但特别标明指定的程序。
  • -l  采用长列格式显示树状图。
  • -n  用程序识别码排序。预设是以程序名称来排序。
  • -p  显示程序识别码。
  • -u  显示用户名称。
  • -U  使用UTF-8列绘图字符。
  • -V  显示版本信息。

2、示例

root@NanoPC:/wan# pstree -apnh  
init,1
  |-upstart-udev-br,1553 --daemon
  |-systemd-udevd,1559 --daemon
  |-hwservice,1697
  |   |-{hwservice},1704
  |   |-{hwservice},1710
  |   |-{hwservice},1712
  |   |-{hwservice},1713
  |   |-{hwservice},1716
  |   |-{hwservice},3037
  |   `-{hwservice},3038
  |-rsyslogd,1785
  |   |-{rsyslogd},1793
  |   |-{rsyslogd},1794
  |   `-{rsyslogd},1795
  |-upstart-file-br,1925 --daemon
  |-smbd,2393 -F
  |   `-smbd,2804 -F
  |-mDNSResponderPo,2561 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2629 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2675 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2728 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2766 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-nmbd,2793 -D
  |-mDNSResponderPo,2795 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2803 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2820 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2835 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2839 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2851 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2857 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2865 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2876 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2879 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2899 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-mDNSResponderPo,2916 -v 1 -r -n FABoard -b -t _http._tcp. -p 9090
  |-getty,2925 -8 38400 tty4
  |-getty,2926 -8 38400 tty5
  |-getty,2929 -8 38400 tty2
  |-getty,2930 -8 38400 tty3
  |-getty,2933 -8 38400 tty6
  |-sshd,2948 -D
  |   `-sshd,3049    
  |       `-bash,3068
  |           `-pstree,14186 -apnh
  |-cron,2958
  |-login,2988 -f     
  |   `-bash,3015
  |-getty,2990 -8 38400 tty1
  `-upstart-socket-,3030 --daemon

你可能感兴趣的:(Linux,命令)