gdb Thread Dumps
Luke Hebert
- 2 minutes read - 237 wordsWhen Apache is stuck, a thread dump tells you exactly where each worker is blocked. You do not need to restart the service or attach a debugger permanently. Three commands in gdb give you a complete backtrace of every thread, then you detach cleanly.
Prerequisites
- You have root or sudo access on the target host.
gdbis installed (yum install gdborapt install gdb).- You know the PID of the
httpdprocess (check withps aux | grep httpd).
Steps
Attach gdb to the running httpd process:
gdb /usr/sbin/httpd <pid>Replace
<pid>with the actual process ID. gdb will pause the process while attached.Print a backtrace for every thread:
(gdb) thread apply all btThis outputs a stack trace for each thread. Look for threads stuck in
futex_wait,poll, or a specific handler function to identify the bottleneck.Detach gdb so httpd resumes normal operation:
(gdb) detachThe process continues running as if gdb was never attached.
Tips
- If the output is long, redirect it:
thread apply all bt > /tmp/httpd_threads.txt(run inside gdb). - Repeat the dump a few seconds apart if you suspect a race condition or intermittent hang.
- Detach promptly. Leaving gdb attached freezes the process and will cause clients to time out.
Attaching gdb to a production httpd process pauses all threads until you detach. Schedule this during a low-traffic window or be ready to detach within seconds.