两个进程可以通过跟踪附加到同一个 PID 吗?

Can two process attach to same PID via ptrace

本文关键字:同一个 PID 跟踪 两个 可以通过 进程      更新时间:2023-10-16

所以,标题说明了一切。

一个进程是否有可能有两个示踪剂?

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

我有两个程序(跟踪器和跟踪(。我在调试模式下运行跟踪,然后我运行跟踪器,并得到错误操作不允许(即使具有root权限(。

问候 戈洛比奇

他们不能。在 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).