title: How to solve "ptrace operation not permitted" when trying to attach GDB to a process?
body: <p>I'm trying to attach a program with gdb but it returns:</p>
  
  <blockquote>
    <p>Attaching to process 29139<br>
        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<br>
        ptrace: Operation not permitted.</p>
  </blockquote>
  
  <p>gdb-debugger returns "Failed to attach to process, please check privileges and try again."</p>
  
  <p>strace returns "attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted"</p>
  
  <p>I changed "kernel.yama.ptrace_scope" 1 to 0 and <code>/proc/sys/kernel/yama/ptrace_scope</code> 1 to 0 and tried <code>set environment LD_PRELOAD=./ptrace.so</code> with this:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int ptrace(int i, int j, int k, int l) {
      printf(" ptrace(%i, %i, %i, %i), returning -1\n", i, j, k, l);
      return 0;
  }
  </code></pre>
  
  <p>But it still returns the same error. How can I attach it to debuggers?</p>