Skip to content

Instantly share code, notes, and snippets.

@kmark
Created February 20, 2015 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmark/7dbf864d7e0fa4bf35df to your computer and use it in GitHub Desktop.
Save kmark/7dbf864d7e0fa4bf35df to your computer and use it in GitHub Desktop.
Finds a running CLion instance and takes multiple jstack traces at a specified interval. Changing the regex should allow for use in any Java process that can be uniquely identified via jps.
#!/bin/bash
traces=10
interval=5
jps -mv | while read -r line; do
if [[ $line =~ ^([0-9]+).*clion.*$ ]]; then
printf "CLion running with PID %s\n" ${BASH_REMATCH[1]}
for ((i = 1; i <= $traces; i++)); do
printf "%d... " $i
jstack -l ${BASH_REMATCH[1]} > jstack-$i.txt
if (("$i" < "$traces")); then
sleep $interval
fi
done
printf "\n"
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment