#!/bin/bash
#输入占用CPU较高的进程号
pid=$
if [ -z $pid ]
then
echo "PID is NULL"
exit
fi
#找到该进程中占用较高的前30个线程号
ps -mp ${pid} -o THREAD,tid,time | sort -rn |head - >mytmp.out
#获取线程信息
while read line
do
tid=`echo $line | awk '{print $8}'`
echo $tid
if [ "${tid}" = "-" ]
then
echo "this is '-'"
else
echo "TID is :"$tid>>${pid}_busy_thread.log
sixteenth=`printf "%x" $tid`
echo "Transform to 0xxxx is :"$sixteenth >>${pid}_busy_thread.log
/home/service/jdk1..0_29/bin/jstack ${pid} | grep $sixteenth -A >>${pid}_busy_thread.log
fi
done <mytmp.out
echo "Finished!"