I've coded a script and am wondering about it's reliability / portability.
#!/bin/bash
threadsPlease() {
ps -mo lwp,c -p $1 | sort -gk 2 | uniq -f 1
}
THREAD_LINE=$( threadsPlease $1 | grep -v - | tail -1)
THREAD10=$(echo $THREAD_LINE | awk '{print $1}')
THREAD16=$(printf '%x\n' $THREAD10)
JAVA_LINE=$(jstack $1 | grep $THREAD16)
echo "OS data (thread, CPU usage %): " $THREAD_LINE
echo "Java thread: " $JAVA_LINE
Script displays system and Java thread data, given Java PID. Sample execution:
./whichThreadIsIt.sh 6814
OS data (thread, CPU usage %): 6838 3
Java thread: "AWT-EventQueue-0" #19 prio=6 os_prio=0 tid=0x00007f50f4090800 nid=0x1ab6 waiting on condition [0x00007f510dfbb000]
Q1: Aside from the obvious ("jstack/java/awk/... is not available or not in path" or "input data given wrongly"), when this will not work the intended way (Ubuntu/Debian)?
Q2: "It's easier to port a shell, than a shell-script", my friend likes to say. So, how much more effort this would need to work in Fedora / CentOS, Free BSD and Solaris? Am I wrong expecting it to run without troubles (assuming Bash present on those boxes)?