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

From NovaOrdis Knowledge Base
Revision as of 04:05, 22 April 2017 by Ovidiu (talk | contribs) (Created page with "<pre> #!/bin/bash function java-process-pid() { ps -ef | grep "java \-jar.*threads\.jar" | grep -v "grep" | awk '{print $2}' } function thread-count() { pid=$1...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
#!/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}