How does strace connect to an already running process?

后端 未结 2 1480
迷失自我
迷失自我 2021-01-30 17:11

I do know that strace uses ptrace to do the job,

but it needs to run the target process with TRACE_ME on,

which don\'t app

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-30 17:19

    The details of ptrace() are OS-specific.

    On Linux, a child may request to be traced by its parent with ptrace(PTRACE_TRACEME, ...); but, alternatively, a process may attach itself to another process with ptrace(PTRACE_ATTACH, ...).

    See the Linux ptrace(2) man page (and, if you really want the fine details, the strace source, and kernel source starting at kernel/ptrace.c).

提交回复
热议问题