4

I start up a jvm process on a linux platform, like tomcat web container. start up command-line :

nohup sh > nohup.out 2>&1 &

When i take a "kill -3 " command, the thread dump information will output to the nohup.out file.

How can i redirect the output to a file singly ?

The Sun HotSpot JVM it's own toolkit from jdk 1.5 which is called jstack, it's very useful by using Sun HotSpot JVM, but the JRockit JVM and HP HotSpot JVM, IBM J9 VM are unsuited.

How can wirte a good generality toolkit to redirect the thread dump information to a single file, and not be stdout file ?

tdy218
  • 53
  • 1
  • 7

2 Answers2

2

It is part of the standard unix process protection policy that after the start of a program no more redirections for its streams can be done without the active help of that program.

But if you don't care that the threaddump is still in nohup.out and additionally in some other file you can do it like this:

tail -f nohup.out > my_new_threaddump &
kill -3 $pid_target_process
kill %+
A.H.
  • 63,967
  • 15
  • 92
  • 126
  • 1
    It refers to the last startend background job. See `man bash` searching for `jobspec`. – A.H. Nov 20 '15 at 07:36
0

Of interest is the related kill -3 to get java thread dump, including Vadzim answer:

-XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=jvm.log

However, this isn't (or at least didn't use to be) compatible with JRockit etc - e.g. see http://blog.eisele.net/2011/01/running-glassfish-with-jrockit.html

Community
  • 1
  • 1
Aled Sage
  • 766
  • 7
  • 12