How do I debug a running process without stopping it?

Quick Linux Tip #11:

Try: sudo gdb -p 1234 -batch -ex 'thread apply all bt' -ex 'quit'

Info: gdb can attach to running processes and dump stack traces without stopping them. Essential for debugging production issues where you cannot restart the service.

Examples:

  • $ sudo gdb -p $(pgrep nginx) -batch -ex 'bt'
  • $ sudo strace -p 1234 -f -e trace=network
  • $ sudo perf record -p 1234 -g sleep 30

Note: gdb briefly pauses the process. For production, use perf or strace for less impact. Requires debug symbols for best results.




LinuxTeck.com
linuxteck@ubuntu:~$ sudo gdb -p 1234 -batch -ex 'thread apply all bt' -ex 'quit'

Attaching to process 1234
Thread 5 (Thread 0x7f8a1234):
#0  0x00007f8a5678 in poll () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x0000555555555678 in event_loop () at server.c:245
#2  0x0000555555555123 in main () at server.c:512

Detaching from process 1234
linuxteck@ubuntu:~$

PREVIOUS ARTICLE Quick Linux Tip #10: How do I capture only specific HTTP traffic to a specific host? NEXT ARTICLE Quick Linux Tip #12: How do I find which process is slowly eating my RAM?
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.