How to solve “ptrace operation not permitted” when trying to attach GDB to a process?

前端 未结 13 2223
予麋鹿
予麋鹿 2020-11-30 18:28

I\'m trying to attach a program with gdb but it returns:

Attaching to process 29139
Could not attach to process. If your uid matches the ui

13条回答
  •  误落风尘
    2020-11-30 19:20

    Just want to emphasize a related answer. Let's say that you're root and you've done:

    strace -p 700
    

    and get:

    strace: attach: ptrace(PTRACE_SEIZE, 700): Operation not permitted
    

    Check:

    cat /proc/700/status | grep TracerPid
    

    If you see something like TracerPid: 12, i.e. not zero, that's the PID of the program that is already using the ptrace system call. Both gdb and strace use it, and there can only be one active at a time.

提交回复
热议问题