@@ -17,7 +17,7 @@ readonly -a COMMAND_LINE=("$0" "$@")
1717readonly USER=" ` whoami` "
1818
1919# ###############################################################################
20- # utils funtions
20+ # util funtions
2121# ###############################################################################
2222
2323# NOTE: $'foo' is the escape sequence syntax of bash
@@ -190,22 +190,20 @@ printStackOfThreads() {
190190 (( counter++ ))
191191 local jstackFile=/tmp/${uuid} _${pid}
192192 [ -f " ${jstackFile} " ] || {
193- {
194- if [ " ${user} " == " ${USER} " ]; then
195- # run without sudo, when java process user is current user
196- " $jstack_path " ${force} $mix_native_frames $more_lock_info ${pid} > ${jstackFile}
197- elif [ $UID == 0 ]; then
198- # if java process user is not current user, must run jstack with sudo
199- sudo -u " ${user} " " $jstack_path " ${force} $mix_native_frames $more_lock_info ${pid} > ${jstackFile}
200- else
201- # current user is not root user, so can not run with sudo; print error message and rerun suggestion
202- redPrint " [$counter ] Fail to jstack busy(${pcpu} %) thread(${threadId} /${threadId0x} ) stack of java process(${pid} ) under user(${user} )."
203- redPrint " User of java process($user ) is not current user($USER ), need sudo to rerun:"
204- yellowPrint " sudo ${COMMAND_LINE[@]} "
205- normalPrint
206- continue
207- fi
208- } || {
193+ if [ " ${user} " == " ${USER} " ]; then
194+ # run without sudo, when java process user is current user
195+ " $jstack_path " ${force} $mix_native_frames $more_lock_info ${pid} > ${jstackFile}
196+ elif [ $UID == 0 ]; then
197+ # if java process user is not current user, must run jstack with sudo
198+ sudo -u " ${user} " " $jstack_path " ${force} $mix_native_frames $more_lock_info ${pid} > ${jstackFile}
199+ else
200+ # current user is not root user, so can not run with sudo; print error message and rerun suggestion
201+ redPrint " [$counter ] Fail to jstack busy(${pcpu} %) thread(${threadId} /${threadId0x} ) stack of java process(${pid} ) under user(${user} )."
202+ redPrint " User of java process($user ) is not current user($USER ), need sudo to rerun:"
203+ yellowPrint " sudo ${COMMAND_LINE[@]} "
204+ normalPrint
205+ continue
206+ fi || {
209207 redPrint " [$counter ] Fail to jstack busy(${pcpu} %) thread(${threadId} /${threadId0x} ) stack of java process(${pid} ) under user(${user} )."
210208 normalPrint
211209 rm ${jstackFile}
0 commit comments