首页 > 解决方案 > 两个进程可以通过 ptrace 附加到同一个 PID

问题描述

所以,标题说明了一切。

一个进程有可能有两个跟踪器吗?

我正在玩 ptrace,我可以看到每当有人附加到进程时,然后在 TracerPID 下的 /proc//status 中将是跟踪器的 PID。但是,是否可以有两个示踪剂?

我有两个程序(tracer 和 tracee)。我在调试模式下运行 tracee,然后运行 ​​tracer,并得到错误 Operation not allowed(即使具有 root 权限)。

问候,戈洛比奇

标签: c++linuxprocessptrace

解决方案


他们不能。在 ptrace 手册页中间接确认了这一点:

   EPERM  The  specified  process cannot be traced.  This could be because
          the tracer has insufficient privileges (the required  capability
          is  CAP_SYS_PTRACE);  unprivileged  processes  cannot trace pro‐
          cesses that they cannot send signals to or  those  running  set-
          user-ID/set-group-ID  programs,  for  obvious reasons.  Alterna‐
          tively, the process may already be being traced, or (on  kernels
          before 2.6.26) be init(1) (PID 1).

推荐阅读