gdb cannot attach to process

Ted picture Ted · Jul 18, 2017 · Viewed 10.5k times · Source

Here is the OS I am using:

Linux securecluster 4.9.8-moby #1 SMP Wed Feb 8 09:56:43 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

When trying to attach gdb to hanging process as root user, I got the following:

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.

I modified /etc/sysctl.d/10-ptrace.conf , resulting in:

kernel.yama.ptrace_scope = 0

However, I got the same error. I tried changing /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

Hint is appreciated.

Answer

Employed Russian picture Employed Russian · Jul 18, 2017

I modified /etc/sysctl.d/10-ptrace.conf

This will only take effect on next reboot.

Until then, just do sudo sysctl -w kernel.yama.ptrace_scope=0