mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
as.sh support jps crash. #2487
This commit is contained in:
@@ -393,12 +393,32 @@ update_if_necessary()
|
||||
fi
|
||||
}
|
||||
|
||||
# jps command may crash, so need to check it
|
||||
check_jps() {
|
||||
"${JAVA_HOME}/bin/jps" > /dev/null 2>&1
|
||||
local exit_code=$?
|
||||
if [ $exit_code -ne 0 ]; then
|
||||
echo "jps command failed with exit code ${exit_code}" >&2
|
||||
fi
|
||||
return $exit_code
|
||||
}
|
||||
|
||||
call_jps()
|
||||
{
|
||||
if [ "${VERBOSE}" = true ] ; then
|
||||
"${JAVA_HOME}"/bin/jps -l -v
|
||||
check_jps
|
||||
local exit_code=$?
|
||||
if [[ "$exit_code" -eq 0 ]]; then
|
||||
# jps command is ok
|
||||
local jps_command=("${JAVA_HOME}/bin/jps" "-l")
|
||||
if [ "${VERBOSE}" = true ] ; then
|
||||
jps_command=("${JAVA_HOME}/bin/jps" "-l" "-v")
|
||||
fi
|
||||
local jps_output=$("${jps_command[@]}")
|
||||
echo "$jps_output"
|
||||
else
|
||||
"${JAVA_HOME}"/bin/jps -l
|
||||
# jps command failed, use ps and grep
|
||||
ps_output=$(ps aux | grep java | grep -v grep | awk '{print $2" "$11}')
|
||||
echo "$ps_output"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user