Nifty little trick for debugging frozen applications
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:
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....
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....
Labels: application development, Linux, programming
3 Comments:
I always use 'kill -9' - never wondered about the 9 until I read your post - looked it up (here) - might have to change my habits!
BTW, none of your poster links work.
cheers.
Thanks for pointing out that the posters don't work. I forgot to copy them over when I moved servers! I'll fix them this weekend.
They've all been fixed now. Thanks again.
Post a Comment
<< Home