1

I want to ptrace-attach to a process that has been paused by sending SIGSTOP to it. I then want to continue running the process under ptrace.

However, it seems that when attaching to a process that is already in a stopped state when attaching - then I cannot continue running it (by sending it a SIGCONT). Only once I detach can it continue to run.

Consider this code:

::kill(pid, SIGSTOP);
::waitpid(pid, &status, WUNTRACED);
::ptrace(PTRACE_ATTACH, pid, 0, 0);
::waitpid(pid, &status, __WALL);
::kill(pid, SIGCONT);
::waitpid(pid, &status, WCONTINUED);
::ptrace(PTRACE_CONT, pid, 0, 0); //or ::ptrace(PTRACE_CONT, tid, 0, SIGCONT)
::waitpid(pid, &status, __WALL);

All of these calls succeed as expected, but the process does not run. It remains in a stopped state. Once I call ptrace_detach (or terminate the tracer) the process continues executing.

So how can I attach to a stopped process, then continue running it under ptrace? Is it possible at all?

(I am on a Ubuntu 20.04 kernel 5.11)

bernd feinman
  • 324
  • 2
  • 11

0 Answers0