Linux PTRACE_ATTACH 不允许用于

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18368817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:37:45  来源:igfitidea点击:

PTRACE_ATTACH not permitted for

clinuxprocessptrace

提问by user2705045

For some reason i am not able to attach to my very own processes?! Works fine if i try straceas root.

出于某种原因,我无法附加到我自己的进程?!如果我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

Running on lubuntu 13.10

在 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

So then how does gdbattach to user's own processes without having to muck around with kernel settings (ptrace_scope)??

那么如何gdb附加到用户自己的进程而不必处理内核设置(ptrace_scope)??

采纳答案by Chris Dodd

Looks like you answered your own question -- you have ptrace_scope set to 1, so you can only trace direct children. To allow tracing any process belonging to the same user, set it to 0. This is also required to use the gdb attachcommand.

看起来您回答了自己的问题——您将 ptrace_scope 设置为 1,因此您只能跟踪直接子级。要允许跟踪属于同一用户的任何进程,请将其设置为 0。这也是使用 gdbattach命令所必需的。

READ the /etc/sysctl.d/10-ptrace.conf file as your error message suggested...

按照错误消息的建议阅读 /etc/sysctl.d/10-ptrace.conf 文件...

回答by Marc Merlin

If this fails as root, I had a problem stracing enlightenment (e17) and the reason was that you can't strace a process already being straced or run under gdb, which some programs will do so that they can get their own debugging info.

如果作为 root 失败,我在追踪启蒙 (e17) 时遇到问题,原因是您无法追踪已经被追踪的进程或在 gdb 下运行,某些程序会这样做,以便他们可以获得自己的调试信息。

回答by Lukasz Czerwinski

If strace fails as root, try checking whether... gdbor straceis not running in the background (that was my case).

如果使用strace以root失败,请检查是否......gdb还是strace没有在后台运行(这是我的情况)。

Command: ps aux | grep "gdb\|strace"

命令: ps aux | grep "gdb\|strace"