Once it happened to me, a ruby application which i wrote took 100% CPU (sometimes) and it hangs the other processes too. Now i need to figure out, where ?. Since it happens once in a while, i could not able to simulate it. Then i search for "inspecting a live ruby process", and i got a very wonderful,useful article
To make it easier, u can save the following few lines of code, to a file (say gdb_inspect.sh)
set $ary = (int)backtrace(-1)
set $count = *($ary+8)
set $index = 0
while $index < $count
x/1s *((int)rb_ary_entry($ary, $index)+12)
set $index = $index + 1
endnow start the gdb,
$gdb ruby <pid>which starts a gdb session,
(gdb) source path/to/gdb_inspect.sh
.
.This shows currently, where the control resides.
.
(gdb)In addition to this,Its also possible to inspect the value of a variable,
which is also explained in that article. After running the same 2-3 times with the pid of my ruby app.
i figured out the problem.
