根据ptrace手册页,
If the PTRACE_O_TRACEEXEC option is not in effect, all successful calls to execve(2) by the traced process will cause it to be sent a SIGTRAP signal, giving the parent a chance to gain control before the new program begins execution.
如果该选项生效,
Stop the tracee at the next execve(2). A waitpid(2) by the tracer will return a status value such that
status>>8 == (SIGTRAP | (PTRACE_EVENT_EXEC<<8))
. If the execing thread is not a thread group leader, the thread ID is reset to thread group leader’s ID before this stop. Since Linux 3.0, the former thread ID can be retrieved with PTRACE_GETEVENTMSG.
因此,如果未设置该选项,则tracee将获得SIGTRAP并停止,以便跟踪器可以获得控制权.如果设置了该选项,则tracee将获得SIGTRAP并停止.有什么区别(除了最后的线程部分)?
最佳答案 差异不在于tracee方面,而在于示踪方.没有该选项,跟踪器无法区分PTRACE_EVENT停止跟随execve和传入的SIGTRAP;它不能使用PTRACE_GETEVENTMSG;另外,交付方式不同:如果我没有弄错,如果SIGTRAP已经挂起,则没有选项.它没有重新排队(像往常一样非实时信号).