kill -3 or jstack : What is the difference?
Asked Answered
B

3

17

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 !

Bemba answered 3/6, 2013 at 14:49 Comment(0)
P
21

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.

Plinth answered 3/6, 2013 at 14:56 Comment(3)
+1 Jstack also allows you to send the stack output to a file while kill -3 (or QUIT) sends it to the console. But if your OS supports kill, the output should be the same.Clairclairaudience
Not always. For me, jstack -F 1138 printed just: Thread 1138: (state = IN_JAVA) and kill -3 1138 printed Full thread dump... "ActorSystem-scheduler-1" #14 prio=5 os_prio=0 tid=0x00007fddb4f58800 nid=0x472 runnable [0x00007fdda4124000] java.lang.Thread.State: RUNNABLEChromosphere
- Does Oracle recommend using one instead of the other? - Are both maintained (not deprecated) in recent versions of Java? - Are both available in both JRE/JDK? - What differences in the output?Estrin
C
2

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)
Cataclysm answered 2/4, 2018 at 20:14 Comment(0)
A
-1

In Windows you have something called "taskkill /PID {yourpid} /F" for killin process. The process id can be obtained from netstat command or use viusal vm to know process id

Allyl answered 3/4, 2018 at 8:53 Comment(1)
This question is not about terminating processes.Estrin

© 2022 - 2024 — McMap. All rights reserved.