$ps -Lp 179093 cu | morejava
USER PID LWP %CPU NLWP %MEM VSZ RSS TTY STAT START TIME COMMAND admin 179093 179093 0.0 383 54.5 5803448 4572012 ? Sl Aug05 0:00 java admin 179093 179097 0.0 383 54.5 5803448 4572012 ? Sl Aug05 0:01 java admin 179093 179100 0.0 383 54.5 5803448 4572012 ? Sl Aug05 8:43 java admin 179093 179101 0.0 383 54.5 5803448 4572012 ? Sl Aug05 8:43 java admin 179093 179102 0.0 383 54.5 5803448 4572012 ? Sl Aug05 8:44 java admin 179093 179103 0.0 383 54.5 5803448 4572012 ? Sl Aug05 8:45 java admin 179093 179104 0.0 383 54.5 5803448 4572012 ? Sl Aug05 2:21 java admin 179093 179105 0.0 383 54.5 5803448 4572012 ? Sl Aug05 55:50 java admin 179093 179106 0.0 383 54.5 5803448 4572012 ? Sl Aug05 0:03 java admin 179093 179107 0.0 383 54.5 5803448 4572012 ? Sl Aug05 0:15 java admin 179093 179108 0.0 383 54.5 5803448 4572012 ? Sl Aug05 0:00 java admin 179093 179109 0.0 383 54.5 5803448 4572012 ? Sl Aug05 0:00 java admin 179093 179110 0.0 383 54.5 5803448 4572012 ? Sl Aug05 1:02 java admin 179093 179111 0.0 383 54.5 5803448 4572012 ? Sl Aug05 0:58 java admin 179093 179112 0.0 383 54.5 5803448 4572012 ? Sl Aug05 0:00 java admin 179093 179113 0.0 383 54.5 5803448 4572012 ? Sl Aug05 29:21 java ......
$printf "%x\n" 179105
2bba1apache
$jstack -l 179093 > jstack.log
$vi jstack.logsocket
search 2bba1.net
"Reference Handler" daemon prio=10 tid=0x00002aaaab073800 nid=0x2bba2 in Object.wait() [0x00000000405cd000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:503) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133) - locked <0x0000000772d40fd8> (a java.lang.ref.Reference$Lock) Locked ownable synchronizers: - None "main" prio=10 tid=0x00002aaaab072000 nid=0x2bb99 runnable [0x0000000041e45000] java.lang.Thread.State: RUNNABLE at java.net.PlainSocketImpl.socketAccept(Native Method) at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:398) at java.net.ServerSocket.implAccept(ServerSocket.java:530) at java.net.ServerSocket.accept(ServerSocket.java:498) at org.apache.catalina.core.StandardServer.await(StandardServer.java:466) at org.apache.catalina.startup.Catalina.await(Catalina.java:787) at org.apache.catalina.startup.Catalina.start(Catalina.java:733) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:320) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:454) Locked ownable synchronizers: - None "VM Thread" prio=10 tid=0x00002aaaab10d000 nid=0x2bba1 runnable "Gang worker#0 (Parallel GC Threads)" prio=10 tid=0x00002aaaab108800 nid=0x2bb9c runnable "Gang worker#1 (Parallel GC Threads)" prio=10 tid=0x00002aaaab109800 nid=0x2bb9d runnable "Gang worker#2 (Parallel GC Threads)" prio=10 tid=0x00002aaaab10a000 nid=0x2bb9e runnable "Gang worker#3 (Parallel GC Threads)" prio=10 tid=0x00002aaaab10a800 nid=0x2bb9f runnable "Concurrent Mark-Sweep GC Thread" prio=10 tid=0x00002aaaab10c000 nid=0x2bba0 runnable "VM Periodic Task Thread" prio=10 tid=0x00002aaaab10d800 nid=0x2bba9 waiting on condition JNI global references: 343 ......
here is a script:code
#!/bin/sh # write by : oldmanpushcart@gmail.com # date : 2014-01-16 # version : 0.07 typeset top=${1:-10} typeset pid=${2:-$(pgrep -u $USER java)} typeset tmp_file=/tmp/java_${pid}_$$.trace /opt/taobao/java/bin/jstack $pid > $tmp_file ps H -eo user,pid,ppid,tid,time,%cpu --sort=%cpu --no-headers\ | tail -$top\ | awk -v "pid=$pid" '$2==pid{print $4"\t"$6}'\ | while read line; do typeset nid=$(echo "$line"|awk '{printf("0x%x",$1)}') typeset cpu=$(echo "$line"|awk '{print $2}') awk -v "cpu=$cpu" '/nid='"$nid"'/,/^$/{print $0"\t"(isF++?"":"cpu="cpu"%");}' $tmp_file done rm -f $tmp_file