start gdb using a pid start gdb using a pid c c

start gdb using a pid


In addition to the previous you can directly use

gdb -p <pid>


There are two ways.

From the command line, include the pid as an argument after the executable name:

gdb /path/to/prog PID

From within gdb, you can use the attach command:

gdb /path/to/proggdb> attach PID

While the specifying on the command line is more concise, there is a slight risk that if you have a core file that has a name that is the same as the pid (i.e. for pid 2345, the core file would have to be named "2345") then gdb will open the core file. Admittedly, the chance of this happening is minuscule.


From the gdb man page:

You can, instead, specify a process ID as a second argument, if you want to debug a running process:

gdb program 1234