2

I have tried jstack -l <PID> >> dump.log and the dump.log file created with no content. Although I could see the thread dump in the terminal where the Java application was running but I need the thread dump in a file. Moreover there is a message at the jstack output: Unable to open socket file: target process not responding or HotSpot VM not loaded.

I tried running java and jstack both by the system user but still no luck getting the pitut redirected to a file. I have used both java 8 and 9.

PS: I have googled about this issue and found people experiencing inconsistencies with having an outut file of jstack or jmap. Kindly let me know if you have any working solution to the problem.

sanjeev
  • 458
  • 1
  • 6
  • 15
  • I had multiple JVMs (Oracle 1.8.0_172 and OpenJDK 1.8.0_171) installed in my system. I didn't notice this yesterday. Today I ran the jstack and jmap commands using full path `sudo /opt/JDK/jdk1.8.0_172/bin/jstack -l 9669 > jstack.dump` and it worked!! Thank you. – sanjeev Jul 29 '18 at 08:04

1 Answers1

1

You can get the thread dump by the following command:

sudo jstack <PID> > a.txt

The above should work because you mentioned that you can see the thread dump on the terminal.

But you also mentioned that jstack outputs

Unable to open socket file: target process not responding or HotSpot VM not loaded.

Hence, there might be a problem with your process itself, and I think it is not loaded properly. Resolve that issue, and the jstack should work for you.


Another issue might be that you might have exhausted the number of open files in your system. Run the following 2 commands.

  • Find open files limit per process: ulimit -n
  • Count all opened files by all process: lsof | wc -l

If the output is same for both of the above commands, you probably have exhaused the total file open limits. And hence, you are not able to write the output into a file. Close the open fd's and that should solve the issue.

Pankaj Singhal
  • 15,283
  • 9
  • 47
  • 86
  • Hi @Pankaj, I forgot to mention that using sudo aslo returned the same message: `Unable to open socket`. Here is the out put of the commands you suggested: `sanjeev@sg src $ ulimit -n 1024 sanjeev@sg src $ lsof | wc -l 335298` I have to resolve the issue with opening the socket. I guess that's what it uses to write to a file. – sanjeev Jul 28 '18 at 16:33
  • can you also post the output of `cat /proc/sys/fs/file-nr`? – Pankaj Singhal Jul 28 '18 at 16:53
  • 1
    If the output is still > 1024, follow this [question](https://stackoverflow.com/questions/34588/how-do-i-change-the-number-of-open-files-limit-in-linux) and try to increase the ulimit of your OS. This should solve your problem – Pankaj Singhal Jul 28 '18 at 16:56