>This trick is just too cool not to mention. I was trying to debug an application that was getting stuck in an endless loop, the other day. It was a rather complicated set of changes that was required and I had no idea where the program was getting stuck.’
In the past, I would have just ended the program with a control-c, and then started dropping in print statements until I could isolate exactly where the program was getting stuck. Instead, I stumbled upon a very nifty little trick: using the kill function to halt the program and dump the thread’s core to screen with the command:
kill -3 [pid]
For a java code running from the class files, the core dump shows you exactly which line is being executed in each thread, allowing you to find out precisely where the problem is – making debugging go much more quickly.
Anyhow, I haven’t yet tried if this works on a .jar file, or what else you can do with a quick “kill -3”, but this certainly broadens my toolkit of debugging utilities, and gives me a whole new respect for the kill signals. I may have to test out a few of the other ones….