Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kill -3 or jstack : What is the difference?

I want to get the thread dump of my web app that running on a jboss server.

I found two solutions for my problem :

  • Using the unix command : kill -3
  • Using the jstack tool that exists in the JDK.

Can anyone explain to me the difference between theses two methods?

Thanks in advance !

like image 877
Anass Avatar asked Jun 03 '13 14:06

Anass


People also ask

What is Jstack for?

Description. The jstack command prints Java stack traces of Java threads for a specified Java process. For each Java frame, the full class name, method name, byte code index (BCI), and line number, when available, are printed. C++ mangled names aren't demangled.

What is JMap and Jstack?

JMap and JStack are probably the most valuable utilities in the toolbox of any Java developer. With the functionality of both these tools combined, you can debug issues and run diagnostics for the java program you're coding.

What is Jstack thread dump?

jstack is a command-line JDK utility we can use to capture a thread dump. It takes the pid of a process and displays the thread dump in the console. Alternatively, we can redirect its output to a file. Let's take a look at the basic command syntax for capturing a thread dump using jstack: jstack [-F] [-l] [-m] <pid>


2 Answers

The jstack command can get a thread dump of a program running on a remote machine, and it also works on Windows.

kill -3 only works on local programs, and on Windows there is no kill.

like image 64
Joni Avatar answered Sep 30 '22 06:09

Joni


From the oracle page of jstack:

The output from the jstack pid option is the same as that obtained by pressing Ctrl+\ at the application console (standard input) or by sending the process a QUIT signal.

Also remember that Ctrl+\ is equivalent to a SIGQUIT.

From what is kill -3 (unix.se):

kill -l shows us all signals. Following this hint 3 means SIGQUIT

So basically both of them do exactly the same thing, i.e asking for a coredump. Here are some pointers related to jstack:

  • Jstack performs deadlock detection by default.
  • Regarding official support, from the jstack man page:

    Prints Java thread stack traces for a Java process, core file, or remote debug server. This command is experimental and unsupported.

    This utility is unsupported and might not be available in future release of the JDK. In Windows Systems where the dbgeng.dll file is not present, Debugging Tools For Windows must be installed so these tools work.

Regarding the output difference, its basically the same thing. There is a one to one mapping between the outputs. See my output for the same application to demonstrate the mapping between the statuses of kill -3 and jstack. The mapping between the statuses are:

kill -3         |  Jstack
------------------------------  
RUNNABLE        |  IN_NATIVE
TIMED_WAITING   |  BLOCKED
WAITING         |  BLOCKED (PARK)
like image 40
TheChetan Avatar answered Sep 30 '22 04:09

TheChetan