Debugging a running daemon using gdb
c, daemon, gdb, linux
Solution
Try async mode and "continue &":
Save below to non-stop.gdb
set target-async on
set pagination off
set non-stop on
Then run:
$ gdb -x non-top.gdb
(gdb) !pgrep YOUR-DAEMON
1234
(gdb) attach 1234
(gdb) continue -a &
(gdb)
Problem
I am developing a high traffic network C server application that runs as a daemon. Under some circumstances, the app crashes (always without core). How I can debug the running daemon with gdb to find the place that generates the SIGSEGV? Explanatory notes: I know how to attach using gdb to a running process using attach command After attaching to the process, it stops. If I run then "continue", gdb remains blocked if the program does not crash. If I press CTRL-C, the process is exiting and I am unable to simply detach gdb. So the question is: is there a way to continue the process without the gdb being stuck but being able to detach if the process does not crash?