Skip to content

Instantly share code, notes, and snippets.

@Arbow
Created July 29, 2013 06:00
Show Gist options
  • Save Arbow/6102390 to your computer and use it in GitHub Desktop.
Save Arbow/6102390 to your computer and use it in GitHub Desktop.
Print java process cpu top 5 threads stack, from https://github.com/54chen/jkiller/blob/master/jkiller.sh
#!/bin/sh
export LANG="zh_CN.UTF-8";
export LC_ALL="zh_CN.UTF-8";
LOG_FILE="/tmp/jkiller.log";
JSTACK_FILE="/tmp/jstack.log";
PID="$1";
shift;
i=0;
j="$1";
if [ -z "${j}" ]; then
j=5;
fi
ps -mp ${PID} -o THREAD,tid,time | sort -rn > ${LOG_FILE};
jstack ${PID} > ${JSTACK_FILE};
for LINE in `cat ${LOG_FILE}|gawk -F '-' '{print $4}'|gawk -F ' ' '{print $1}'`
do
i=$(($i+1));
if (($i>$j)); then
break;
fi;
XPID=`printf "%x\n" ${LINE}`;
echo -ne "\033[32m";
echo ${XPID};
echo -e "\033[34m";
grep -A 10 "0x${XPID}" ${JSTACK_FILE};
echo -e "\e[0m";
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment