#!/bin/bash ######################################################## ### Find the details of threads that consume too much CPU resources ### ### 2014-11-03 allen add ########################################################## #Step1 Print the ID of the process that occupies too much CPU top -b -d3 -n1 -u hotel | awk '/PID/,0' > ./_pid_out.out v_pid=`awk 'NR==2 {print $1}' ./_pid_out.out` #Step2 Print the thread IDs that take up too much CPU in the process top -b -d3 -n1 -H -p $v_pid | awk '/PID/,0' > ./_tid_out.out v_tid = `awk 'NR == 2 {print $ 1}' ./_ tid_out.out` #Step3 Convert the thread ID to hexadecimal #echo 'ibase=10;obase=16;$v_tid' | bc v_tid16=`printf %x $v_tid` echo "thread id[hexadecimal] is : 0x${v_tid16}" echo "" #Step4 Print the thread stack of the process with high CPU usage echo "wait 5 seconds, please..." jstack $ v_pid> ./_thread_stack.out sleep 5s #Step5 Find the specific code executed by the thread in _thread_stack.out, print the new line and the 30 lines after it, and highlight the matching content cat ./_thread_stack.out | grep -n --color=auto -A 30 -i 0x${v_tid16} #clean rm -rf ./_pid_out.out rm -rf ./_tid_out.out
When the server fails, query the process and thread that caused the failure
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326466816&siteId=291194637
Ranking