gdb无法附加到进程

Ted*_*Ted 3 linux ptrace gdb docker

这是我正在使用的操作系统:

Linux securecluster 4.9.8-moby#1 SMP 2月8日星期三09:56:43 UTC 2017 x86_64 x86_64 x86_64 GNU / Linux

当尝试以root用户身份将gdb附加到挂起的进程时,得到以下信息:

Attaching to process 9636
Could not attach to process.  If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.
Run Code Online (Sandbox Code Playgroud)

我修改了/etc/sysctl.d/10-ptrace.conf,结果是:

kernel.yama.ptrace_scope = 0
Run Code Online (Sandbox Code Playgroud)

但是,我遇到了同样的错误。我尝试更改/ proc / sys / kernel / yama / ptrace_scope:

echo 0 | tee /proc/sys/kernel/yama/ptrace_scope
tee: /proc/sys/kernel/yama/ptrace_scope: Read-only file system
Run Code Online (Sandbox Code Playgroud)

提示表示赞赏。

Emp*_*ian 9

我修改了/etc/sysctl.d/10-ptrace.conf

这只会在下次重新启动时生效。

到那时,就做 sudo sysctl -w kernel.yama.ptrace_scope=0

  • 我试过这个命令: sysctl -w kernel.yama.ptrace_scope=0 sysctl: setting key "kernel.yama.ptrace_scope": Read-only file system (3认同)
  • @Ted 您是否找到了只读文件系统问题的解决方案? (2认同)

Flo*_*mer 5

您是否在使用容器引擎?尝试从容器外部(在主机上)附加到进程。它在那里可能具有不同的PID。

或者,启动具有此CAP_SYS_PTRACE功能的容器(--cap-add sys_ptrace例如,使用)。当然,如果无法重现挂起,则不能使用此方法。