PID USER PR NI VIRT SHR S %CPU %MEM TIME+ COMMAND 5947 root 20 0 1794m 11m S 0.3 13.6 32:43.55 java 1176 root 20 0 185m 3608 S 0.1 0.2 7:53.12 vmtoolsd 1923 root 20 0 134m 1040 S 0.0 0.5 3:12.59 redis-server
第二步:使用top -Hp命令获取进程中线程信息(其中H:线程可见状态切换,p表示pid),这里最高的线程pid=5958
[root@agx ~]# top -Hp 5947 top - 10:31:55 up 4 days, 20:44, 1 user, load average: 0.00, 0.00, 0.00 Tasks: 47 total, 0 running, 47 sleeping, 0 stopped, 0 zombie Cpu(s): 0.3%us, 0.2%sy, 0.0%ni, 99.5%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 1922208k total, 1795408k used, 126800k free, 368404k buffers Swap: 10485756k total, 1796k used, 10483960k free, 806448k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 5958 root 20 0 1794m 256m 11m S 0.3 13.6 4:47.17 java 5968 root 20 0 1794m 256m 11m S 0.3 13.6 5:14.80 java 5947 root 20 0 1794m 256m 11m S 0.0 13.6 0:00.00 java 5948 root 20 0 1794m 256m 11m S 0.0 13.6 0:01.24 java
第三步:获取最高的线程pid(十进制,装换成十六进制),这里用python -c "print hex(线程PID)"
[root@agx ~]# python -c "print hex(5958)" 0x1746
[root@agx ~]# jstack 5947 | grep -C10 0x1746 at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455) "VM Thread" prio=10 tid=0x00007f9448064000 nid=0x173f runnable "GC task thread#0 (ParallelGC)" prio=10 tid=0x00007f944801e800 nid=0x173d runnable "GC task thread#1 (ParallelGC)" prio=10 tid=0x00007f9448020800 nid=0x173e runnable "VM Periodic Task Thread" prio=10 tid=0x00007f944809b800 nid=0x1746 waiting on condition JNI global references: 234