0

I would like to go like this

jstack ALL

or something like that so i can get the thread dump for all jvms on my system.

Can it be done?

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
Nicholas DiPiazza
  • 10,029
  • 11
  • 83
  • 152
  • You seem to be asking about the (unsupported) [`jstack`](https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstack.html) command that I guess is packaged with some versions of Oracle's Java developer kit. Thus, this isn't really a Java question *per se*, though of course it's Java-related. I've added the [bash] tag, though if you're interested in doing this on Windows then a different one might be a more appropriate. – John Bollinger Apr 01 '16 at 19:58
  • I don't need windows help but it might help someone else – Nicholas DiPiazza Apr 01 '16 at 20:00

2 Answers2

2

The jstack command reference offers these three invocation forms:

jstack [ options ] pid

jstack [ options ] executable core

jstack [ options ] [ server-id@ ] remote-hostname-or-IP

Of those, only the first is relevant to JVMs currently running on the same system where jstack runs. Thus, you must identify the JVM processes by their pids.

In its summary of the pid argument, the reference notes:

To get a list of Java processes running on a machine, use the jps(1) command.

Presumably, if you have jstack available to you then you also have jps. The docs suggest that you might use jps -q to get a listing of only the relevant pids, that you therefore do not need to massage. Given that, you could do something like this in bash:

for vmpid in $(jps -q); do
  jstack $vmpid
done

Evidently jps is implemented in Java, for I find that it reports on itself. If that bothers you then the above could be tweaked to filter out jps itself.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
1

You could run the following in your terminal:

ps -e  | grep [j]ava  | awk '{print $1}' | xargs -n 1 jstack
Reverend Gonzo
  • 39,701
  • 6
  • 59
  • 77