use*_*045 7 c linux ptrace process
出于某种原因,我无法附加到我自己的流程?!如果我strace以root身份尝试,则工作正常.
$ ./list8 &
[1] 3141
$ child4 starts...
$ strace -p 3141
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
$ cat /proc/sys/kernel/yama/ptrace_scope
1
Run Code Online (Sandbox Code Playgroud)
在lubuntu 13.10上运行
Linux goal 3.8.0-19-generic #29-Ubuntu SMP Wed Apr 17 18:19:42 UTC 2013 i686 i686 i686 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
那么如何gdb附加到用户自己的进程而不必破坏内核设置(ptrace_scope)?
看起来你回答了自己的问题 - 你将ptrace_scope设置为1,所以你只能追踪直接的孩子.要允许跟踪属于同一用户的任何进程,请将其设置为0.这也是使用gdb attach命令所必需的.
阅读/etc/sysctl.d/10-ptrace.conf文件作为建议的错误消息...