0

It is common to use ptrace(PTRACE_TRACEME, 0, 0, 0) to prevent a program from being debugged,

But once PTRACE_TRACEME is applied, the program will not exit properly, but rather receives a SIGSTOP signal,

So how should one make the program exit properly? exit(0) will not work here

daisy
  • 22,498
  • 29
  • 129
  • 265

1 Answers1

0

From http://man7.org/linux/man-pages/man2/ptrace.2.html

PTRACE_TRACEME
          Indicate that this process is to be traced by its parent.  A
          process probably shouldn't make this request if its parent
          isn't expecting to trace it.

It is common to use ptrace(PTRACE_TRACEME, 0, 0, 0) to prevent a program from being debugged,

Any such "common" use is broken, unless the parent process is about to trace this one.

You've promised (to the kernel) "I am about to start tracing this process". The kernel dutifully waits for you to fulfill that promise.

So how should one make the program exit properly?

Have the parent trace it (with all that implies).

Employed Russian
  • 199,314
  • 34
  • 295
  • 362