Bash script that reports the number of threads of a Java process

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
#!/bin/bash

function java-process-pid() {

    ps -ef | grep "java \-jar.*threads\.jar" | grep -v "grep" | awk '{print $2}'
}

function thread-count() {

    pid=$1

    cat /proc/${pid}/status | grep "^Threads" | awk '{print $2}'
}

pid=$(java-process-pid)
thread-count ${pid}