#!/bin/bash source /etc/profile #接收外部传入PID,任选一种 #servicePid=$1 headPid=`ps auxw|sort -rn -k3|head -4|sed -n '1,4p'` echo "${headPid}" > headPid.log servicePid=`ps auxw|sort -rn -k3|head -2|sed -n '1p'|awk '{print $2}'` #rm -rf ./jstack.out /alidata/jdk1.7.0_79/bin/jstack -l ${servicePid} > jstack.out #查看该进程的线程情况,排查进程中哪些线程占用率很高,排名前10 showPidmessage=`ps -mp ${servicePid} -o THREAD,tid,time|sort -rn|head -n 10|awk '{print $8}'|sed -n '2,10p'|grep -v '-'` rm -rf ./showMessage.log for i in $showPidmessage do id=`printf '%x ' $i` echo "进程PID:${servicePid},子线程:$i,16进制数值:$id" >> showMessage.log done showPid=`ps -mp ${servicePid} -o THREAD,tid,time|sort -rn|head -n 10|awk '{print $2,$8,$9}'|sed -n '2,10p'|grep -v '-'|sort -rn` echo "线程CPU占用率 线程ID 运行时长" > showPid.log echo "${showPid}" > showPid.log echo "this is ok"