get java version of a running java process
Asked Answered
P

4

15

I can use jps to list running java processes and use jstack -l process_id to get a stack information of a running java process. I want to know this process runs on which java version. Is there a way to do it? I don't have to use jstack tool. thanks.

jstack -l 23819 2014-11-12 12:36:11 Full thread dump OpenJDK 64-Bit Server VM (23.25-b01 mixed mode):

"Attach Listener" daemon prio=10 tid=0x000000000272f800 nid=0x614b waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE

Locked ownable synchronizers: - None

Pseudonymous answered 12/11, 2014 at 20:44 Comment(0)
M
24

You can do it via jcmd, like this:

jcmd process_id VM.version
Martinmartina answered 12/11, 2014 at 21:8 Comment(0)
C
6

In Linux you could do

sudo strings /proc/<java_pid>/smaps |grep jre

which will produce something similar to

7f8ff82ac000-7f8ff82ad000 r-xp 00000000 fd:00 252363860 /usr/java/jdk1.8.0_141/jre/lib/amd64/libjaas_unix.so

From this you can clearly see what JDK version it's using.

Cyrilcyrill answered 27/9, 2017 at 22:36 Comment(1)
In my case I had to grep jvm but thanks for the nice answer.Respective
G
5

A simple solution with standard command would look like:

lsof -p PID | grep jdk

It gives you the list of loaded files by the process.

Giacometti answered 13/10, 2015 at 16:2 Comment(0)
E
0

I think Andrew's solution is better and probably what you are looking for. Nevertheless here's another solution:

ps -A | grep "^ <the pid>" | grep -o "jdk.*.jdk"

Output for a program I was running:

jdk1.8.0_05.jdk
Eisegesis answered 12/11, 2014 at 21:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.