Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can two process attach to same PID via ptrace

So, the title says it all.

Is it possible that one process has two tracers?

I am playing around with ptrace, and I can see that whenever someone attaches to process, then in /proc//status under TracerPID will be PID of the tracer. However, is it possible to have two tracers?

I have two programs (tracer, and tracee). And I ran tracee in debug mode, and then I ran tracer, and got error Operation not permited (even with root permissions).

Regards, golobich

like image 876
golobitch Avatar asked Jan 18 '26 03:01

golobitch


1 Answers

They can't. It is indirectly confirmed in ptrace man page:

   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).
like image 146
grungegurunge Avatar answered Jan 20 '26 17:01

grungegurunge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!