-
Notifications
You must be signed in to change notification settings - Fork 2.8k
增加对非root用户启动的JVM的支持 #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
如果是非root用户启动的JVM,使用这个脚本会报错 3031: well-known file is not secure Fail to jstack java process 3031!
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,12 +19,13 @@ Options: | |
| -p, --pid find out the highest cpu consumed threads from the specifed java process, | ||
| default from all java process. | ||
| -c, --count set the thread count to show, default is 5 | ||
| -u, --user set java process user | ||
| -h, --help display this help and exit | ||
| EOF | ||
| exit $1 | ||
| } | ||
|
|
||
| readonly ARGS=`getopt -n "$PROG" -a -o c:p:h -l count:,pid:,help -- "$@"` | ||
| readonly ARGS=`getopt -n "$PROG" -a -o c:p:u:h -l count:,pid:,help -- "$@"` | ||
| [ $? -ne 0 ] && usage 1 | ||
| eval set -- "${ARGS}" | ||
|
|
||
|
|
@@ -38,6 +39,10 @@ while true; do | |
| pid="$2" | ||
| shift 2 | ||
| ;; | ||
| -u|--user) | ||
| jvmuser="$2" | ||
| shift 2 | ||
| ;; | ||
| -h|--help) | ||
| usage | ||
| ;; | ||
|
|
@@ -93,14 +98,25 @@ printStackOfThread() { | |
| local pcpu=`echo ${threadLine} | awk '{print $5}'` | ||
|
|
||
| local jstackFile=/tmp/${uuid}_${pid} | ||
|
|
||
|
|
||
|
|
||
| [ ! -f "${jstackFile}" ] && { | ||
| jstack ${pid} > ${jstackFile} || { | ||
| redEcho "Fail to jstack java process ${pid}!" | ||
| rm ${jstackFile} | ||
| continue | ||
| } | ||
| } | ||
| if [ `uname -m` == "x86_64" ];then | ||
| flag="-J-d64" # x86-64 specify jstack option "-J-d64" | ||
| fi | ||
| if [ -z ${jvmuser+x} ];then | ||
| # root user | ||
| jstackCmd="$JAVA_HOME/bin/jstack $flag" | ||
| else | ||
| # non-root user use sudo -u user | ||
| jstackCmd="sudo -u $jvmuser $JAVA_HOME/bin/jstack $flag" | ||
|
||
| fi | ||
| $jstackCmd ${pid} > ${jstackFile} || { | ||
| redEcho "Fail to jstack java process ${pid}!" | ||
| rm ${jstackFile} | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| redEcho "[$((count++))] Busy(${pcpu}%) thread(${threadId}/0x${threadId0x}) stack of java process(${pid}) under user(${user}):" | ||
| sed "/nid=0x${threadId0x} /,/^$/p" -n ${jstackFile} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我在 x86_64 的机器上测试了, 并不需要 jstack 命令上 加上 -J-d64 选项。
@liuyangc3 你不加这个选项 碰到的问题是什么?给一下相关的信息 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我测试的时候也发现确实不需要这个选项,oracle官方doc上指出在64位系统上可能需要指定这个参参数,这里确实画蛇添足了