Thanks for visiting my blog - I have now moved to a new location at Nature Networks. Url: - Please come visit my blog there.

Friday, April 10, 2009

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:
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: , ,


Blogger Lavinia said...

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.

April 15, 2009 9:21:00 PM PDT  
Blogger Anthony Fejes said...

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.

April 15, 2009 9:22:00 PM PDT  
Blogger Anthony Fejes said...

They've all been fixed now. Thanks again.

April 16, 2009 11:14:00 PM PDT  

Post a Comment

<< Home