How does one obtain the pid of the currently debugged process in gdb?

前端 未结 2 1297
轮回少年
轮回少年 2021-01-01 14:07

Inside gdb, what command will provide the pid of the process getting debugged?

Most of the google results discuss only how to attach gdb to a process once we know th

2条回答
  •  情话喂你
    2021-01-01 14:40

    One simple way is info inferior. Here I'm debugging gdb with itself and this command shows the PID of the debuggee:

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

    You can also just call the ordinary C function:

    (top-gdb) print getpid()
    $3 = 14068
    

提交回复
热议问题