Skip to content

Commit 2c90f03

Browse files
committed
add fast-fail guard for show-busy-java-threads.sh
1 parent a2bbd6d commit 2c90f03

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

show-busy-java-threads.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
readonly PROG="`basename $0`"
1212
readonly -a COMMAND_LINE=("$0" "$@")
1313

14+
# Check os support!
15+
uname | grep '^Linux' -q || {
16+
echo "$PROG only support Linux, not support `uname` yet!" 1>&2
17+
exit 2
18+
}
19+
1420
# Get corrent current user name via whoami command
1521
# See get https://www.lifewire.com/current-linux-user-whoami-command-3867579
1622
# Because if use `sudo -u` to run command, env var $USER is not rewrited/correct, just inherited from outside!
@@ -187,7 +193,7 @@ printStackOfThreads() {
187193
}
188194

189195
bluePrint "[$((counter++))] Busy(${pcpu}%) thread(${threadId}/${threadId0x}) stack of java process(${pid}) under user(${user}):"
190-
sed "/nid=${threadId0x} /,/^$/p" -n ${jstackFile} | tee ${append_file+-a "$append_file"}
196+
sed "/nid=${threadId0x} /,/^$/p" -n ${jstackFile} | tee ${append_file:+-a "$append_file"}
191197
done
192198
}
193199

0 commit comments

Comments
 (0)