0

I have a multi-threaded process that got stuck while running under Linux. But I don't have multi-threaded version to pstack (made alias with gstack). As such, gstack <pid> does not provide me anything. How can I (a) attach gdb to an already running process (b) get stack trace of individual threads (c) know threadids of a running process (d) from threadid (if known) how can I see the stack trace / call stack for a running thread under stuck process?

Dr. Debasish Jana
  • 6,980
  • 4
  • 30
  • 69
  • For (a) at least, have you read the basic manpage for gdb? For the rest of them, have you read the GDB help pages? – Sneftel Sep 21 '17 at 11:43

1 Answers1

1

At first, compile it with options -O0 -ggdb for best debugging.

If you can run in under gdb, just run

   # gdb ./yourbinary

And just wait problem. When process get stuck, just press ^C and you in.

If you can't run under gdb, just:

   # gdb --pid=<YOUR PID>

At both cases, type info threads and you will see all your threads. Then select one and you can see bt or anything else.

bukkojot
  • 1,526
  • 1
  • 11
  • 16