如何在gdb中获取当前被调试进程的pid? [英] How does one obtain the pid of the currently debugged process in gdb?

查看:25
本文介绍了如何在gdb中获取当前被调试进程的pid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在gdb内部,什么命令会提供被调试进程的pid?

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

大部分google results 仅讨论如何将 gdb 附加到我们知道 pid 后的进程.

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

推荐答案

一种简单的方法是信息劣化.这里我自己调试 gdb,这个命令显示了被调试对象的 PID:

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 

你也可以只调用普通的 C 函数:

You can also just call the ordinary C function:

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

这篇关于如何在gdb中获取当前被调试进程的pid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆