在 Linux 上,检查程序是否在调试器中的一种简单方法是检查 if(ptrace(PTRACE_TRACEME, 0, 0, 0) == -1)
。在此之后我该如何分离? ptrace(PTRACE_DETACH, 0, 0, 0)
不起作用(返回 -1
)。
最佳答案
只有“父”(调试器)可以从被跟踪的子进程中分离出来; child 不可能让自己脱离。 man ptrace
:
PTRACE_TRACEME Indicate that this process is to be traced by its parent. … The PTRACE_TRACEME request is used only by the tracee; the remaining requests are used only by the tracer. …
关于c - 从调用自身的 ptrace 分离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34041565/