Skip to content

Commit d2f48d5

Browse files
committed
fix bug: option parse fail should exit
1 parent 73d1804 commit d2f48d5

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

show-busy-java-threads

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,11 @@ uname | grep '^Linux' -q || fatal "Error: $PROG only support Linux, not support
127127
# parse options
128128
################################################################################
129129

130-
readonly ARGS=`getopt -n "$PROG" -a -o p:c:a:s:S:Pd:Fmlh -l count:,pid:,append-file:,jstack-path:,jstack-file-dir:,use-ps,top-delay:,force,mix-native-frames,lock-info,help -- "$@"`
131-
[ $? -ne 0 ] && usage 1
130+
# NOTE: ARGS can not be declared as readonly!!
131+
# readonly declaration make exit code of assignment to be always 0, aka. the exit code of `getopt` in subshell is discarded.
132+
# tested on bash 4.2.46
133+
ARGS=`getopt -n "$PROG" -a -o p:c:a:s:S:Pd:Fmlh -l count:,pid:,append-file:,jstack-path:,jstack-file-dir:,use-ps,top-delay:,force,mix-native-frames,lock-info,help -- "$@"`
134+
[ $? -ne 0 ] && { echo; usage 1; }
132135
eval set -- "${ARGS}"
133136

134137
while true; do
@@ -275,8 +278,7 @@ __top_threadId_cpu() {
275278
HOME="$tmp_store_dir" top -H -b -d $top_delay -n 2 |
276279
awk '{
277280
if (idx == 3 && $NF == "java") # $NF is command
278-
# only print 4th text block(idx == 3)
279-
# aka. process info of second top update
281+
# only print 4th text block(idx == 3), aka. process info of second top update
280282
print $1 " " $9 # $1 is thread id, $9 is %cpu
281283
if ($0 == "")
282284
idx++

0 commit comments

Comments
 (0)