strace 如何连接到已经运行的进程?

发布于 2024-12-05 11:28:49 字数 164 浏览 1 评论 0原文

我确实知道 strace 使用 ptrace 来完成这项工作,

但它需要在 TRACE_ME 打开的情况下运行目标进程,

这不适用对于已经运行的进程的情况。

它如何在已经运行的进程上工作?

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 apply for the case of an already running process.

how does it work on an already running process?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七秒鱼° 2024-12-12 11:28:49

strace -p ---->将进程附加到strace。 “-p”选项用于进程的PID

strace -e trace=read,write -p -->通过这种方式,您还可以跟踪进程/程序的事件,例如读取和写入(在本例中)。因此,这里它将打印所有此类事件,包括进程的读取和写入系统调用。

其他此类示例

-e trace= network  (Trace all the network related system calls.)

-e trace=signal    (Trace all signal related system calls.)

-e trace=ipc       (Trace all IPC related system calls.)

-e trace=desc      (Trace all file descriptor related system calls.)

-e trace=memory    (Trace all memory mapping related system calls.)

等等。

trace 是可以与 -e 选项一起使用的众多选项之一。

Ctrl-C 中止 strace 的跟踪。

输入 strace -h 查看帮助部分,了解有关 strace 的简要摘要
手册页以获取详细信息。

注意:跟踪的进程运行缓慢。

strace -p <PID> ----> To attach a process to strace. "-p" option is for PID of the process.

strace -e trace=read,write -p <PID> --> By this you can also trace a process/program for an event, like read and write (in this example). So here it will print all such events that include read and write system calls by the process.

Other such examples

-e trace= network  (Trace all the network related system calls.)

-e trace=signal    (Trace all signal related system calls.)

-e trace=ipc       (Trace all IPC related system calls.)

-e trace=desc      (Trace all file descriptor related system calls.)

-e trace=memory    (Trace all memory mapping related system calls.)

and many more..

trace is one of the many options you can use with -e option.

Press Ctrl-C to abbort the tracing by strace.

Check HELP section for brief summary on strace by typing strace -h
and man page for detailed info.

NOTE: A traced process runs slowly.

那些过往 2024-12-12 11:28:49

ptrace() 的详细信息是特定于操作系统的。

在 Linux 上,子进程可以使用 ptrace(PTRACE_TRACEME, ...) 请求其父进程跟踪;但是,进程也可以使用 ptrace(PTRACE_ATTACH, ...) 将自身附加到另一个进程。

请参阅 Linux ptrace(2) 手册页(并且,如果您确实想要详细信息,请使用 strace,以及内核源代码从 kernel/ptrace.c< /a>)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文