linux查看进程与线程信息(pstree pstack jstack)

导言

在日常开发运维中,经常需要对进程及其线程信息进行获取,来排查内存溢出,死锁,阻塞等问题。本文主要是查看进程及其进程堆栈信息

一.PSTREE
pstree [-acGhlnpuUV][-H <程序识别码>][<程序识别码>/<用户名称>
说明:如果不指定程序识别码或用户名称,则会把系统启动时的第一个程序视为基层,并显示之后的所有程序。若指定用户名称,便会以隶属该用户的第一个程序当作基层,然后显示该用户的所有程序。
使用ps命令得到的数据精确,但数据庞大,这一点对掌握系统整体概况来说是不容易的。pstree命令正好可以弥补这个缺憾。它能将当前的执行程序以树状结构显示。pstree命令支持指定特定程序(PID)或使用者(USER)作为显示的起始。

PSTREE(1)                        User Commands                       PSTREE(1)

NAME
       pstree - display a tree of processes

SYNOPSIS
       pstree [-a] [-c] [-h|-Hpid] [-l] [-n] [-p] [-u] [-Z] [-A|-G|-U] [pid|user]
       pstree -V

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.

OPTIONS
       -a     Show command line arguments. If the command line of a process is swapped out, that process is shown in parentheses. -a implicitly disables compaction.

       -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.

       -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 compaction.

       -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   m\033%8 nd  left  with  echo  -e
       -V     Display version information.

       -Z     (SELinux) Show security context for each process.

FILES
       /proc     location of the proc file system

AUTHORS
       Werner Almesberger <[email protected]> Craig Small <[email protected].id.au>

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

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

Linux                             2004-11-09                         PSTREE(1)

问题背景

某日,在主机上不行运行java进程,每次运行都返回 “Error occurred during initialization of VM java.lang.OutOfMemoryError”。
首先认为内存资源已满,或者java OPT参数过低,导致内存不足,故free -g查看后返现机器还有110G内存。故排除,修改启动脚本,-Xmx1g由1G修改为2G,问题依旧。
free -g
此时怀疑是否为线程资源耗干导致,故通过 pstree -p |wc 获取当前用户运行的线程总数,ulimit -u 获取当前用户的最多可运行线程数,果然线程满了.
此时再通过 pstree -p |more 查找到线程id
一个是id为30265的C进程,一个是id为3637的java进程,其中java进程开启了10540个线程,应该是程序逻辑错误,导致线程溢出。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值