Solving `ptrace: Operation not permitted.` for GDB
The Permission Error
If you see this error when attaching the GDB to a process:
ptrace: Operation not permitted.
The Solution
- (Temporarily, sudo required) run
echo "0"|sudo tee /proc/sys/kernel/yama/ptrace_scope
- (Permanently, sudo required) editing the file
/etc/sysctl.d/10-ptrace.conf
and change the line:kernel.yama.ptrace_scope = 1
tokernel.yama.ptrace_scope = 0