Is PTRACE_ATTACH lazy?

From: Victor Zandy (zandy@cs.wisc.edu)
Date: Thu Mar 09 2000 - 18:55:41 EST


    On x86 Linux 2.2.12 a valid ptrace call that closely follows a
successful PTRACE_ATTACH can fail, with error ESRCH.

For example, I find that if I make two calls like this

     ret = ptrace(PTRACE_ATTACH, pid, 0, 0);
     ret = ptrace(PTRACE_DETACH, pid, 0, 0);

the second call will fail, with ESRCH.

However, if I put some time between the calls, like this

     ret = ptrace(PTRACE_ATTACH, pid, 0, 0);
     usleep(100);
     ret = ptrace(PTRACE_DETACH, pid, 0, 0);

then the second call will succeed.

    My guess is that the traced process has not had its state set to
TASK_STOPPED before the second call to ptrace is executed. (Does the
traced process need to be scheduled before it will change to
TASK_STOPPED?)

    Does anyone know for sure why this happens?

    Can anyone suggest a workaround that to allow me make one or
more ptrace calls immediately after a PTRACE_ATTACH?

    Thanks.

Vic Zandy

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Mar 15 2000 - 21:00:17 EST