在linux上,检查程序是否在调试器中的简单方法是检查if(ptrace(PTRACE_TRACEME, 0, 0, 0) == -1)
。我怎么能在这之后分开? ptrace(PTRACE_DETACH, 0, 0, 0)
不起作用(返回-1
)。
答案 0 :(得分:0)
只有“父”(调试器)可以从跟踪的子进程中分离出来;孩子不可能脱离自己。 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. …