How to get pid of current debugged process in gdb?

Inside gdb, which command will provide the pid of the process to be debugged?

Most google results only discuss how to connect gdb to the process when we recognize pid.

+7
c ++ linux gdb
source share
1 answer

One easy way is info inferior . Here I am debugging gdb with myself, and this command shows the PID debuggee:

 (top-gdb) info inferior Num Description Executable * 1 process 14068 /home/tromey/gdb/build/gdb/gdb 

You can also just call the regular C function:

 (top-gdb) print getpid() $3 = 14068 
+7
source share

All Articles