Ubuntu – Why won’t strace/gdb attach to a process even though I’m root

11.1012.04debuggingkernelprogramming

  • I logged in as root but strace gives me this:

    root@kyznecov-System:/home/kyznecov# ps -e | grep 111
     3807 pts/2    00:00:00 111
     3810 pts/2    00:00:00 111
    root@kyznecov-System:/home/kyznecov# strace -p 3810
    
    attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted
    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
    root@kyznecov-System:/home/kyznecov
    
    root@kyznecov-System:/home/kyznecov# cat /proc/sys/kernel/yama/ptrace_scope
    0
  • I then tried to use gdb to debug a multiprocess program in Eclipse CDT with forking, and it gave me the same result/error:

    enter image description here

Any ideas?

Best Answer

One reason to get the error:

attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted

is because the process has already been attached to with gdb, strace or similar. To check if this is the case, run:

grep TracerPid /proc/$THE_PID/status

If it is nonzero, that is the pid of an existing program that is already running a trace on that process.

Related Question