识别导致 strace 挂起的文件

发布于 2024-10-20 04:48:27 字数 367 浏览 5 评论 0原文

我有一个在 Ubuntu 10.04 上运行的 GTK 程序,该程序以可中断状态挂起,我想了解 strace 的输出。特别是,我有这样一行:

read(5, 0x2ba9ac4, 4096) = -1 EAGAIN (Resource temporarily unavailable)

我怀疑 5 是文件描述符,0x2ba9ac4 是要读取的文件中的地址,4096 是要读取的数据量。你能确认一下吗?更重要的是,如何确定程序正在尝试读取哪个文件? /proc/pid/fd 中不存在此文件描述符(这可能是程序挂起的原因)。

I have a GTK program running on Ubuntu 10.04 that hangs in interruptible state, and I'd like to understand the output of strace. In particular, I have this line:

read(5, 0x2ba9ac4, 4096) = -1 EAGAIN (Resource temporarily unavailable)

I suspect 5 is the file descriptor, 0x2ba9ac4 the address in this file to be read, and 4096 the amount of data to read. Can you confirm? More importantly, how can one determine which file the program is trying to read? This file descriptor does not exist in /proc/pid/fd (which is probably why the program hangs).

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

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

发布评论

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

评论(3

诠释孤独 2024-10-27 04:48:27

您可以通过调用strace -o log -eopen,read yourprogram来查找哪个文件使用该文件描述符。然后在 log 文件中搜索对感兴趣的 read 的调用。从这一行(而不是从文件的第一行)开始,向上搜索此文件描述符的第一次出现(通过调用 open 返回)。

例如这里,open返回的文件描述符是3:

open("/etc/ld.so.cache", O_RDONLY)      = 3

You can find which file uses this file descriptor by calling strace -o log -eopen,read yourprogram. Then search in the log file the call to read of interest. From this line (and not from the first line of the file), search upwards the first occurrence of this file descriptor (returned by a call to open).

For example here, the file descriptor returned by open is 3:

open("/etc/ld.so.cache", O_RDONLY)      = 3
流绪微梦 2024-10-27 04:48:27

read() 的第二个参数只是目标指针,它要求从文件描述符 5 读取,最多 4096 字节。请参阅 read() 的手册页

The second argument to read() is simply the destination pointer, it's asking for a read from file descriptor 5, and max 4096 bytes. See the manual page for read().

怪异←思 2024-10-27 04:48:27

添加到 @liberforce 答案,如果进程已经在运行,您可以使用 lsof

形式 strace

[pid  7529] read(102, 0x7fedc64c2fd0, 16) = -1 EAGAIN (Resource temporarily unavailable)

现在使用 lsof获取文件名

lsof -p 7529 | grep 102
java    7529 luis  102u  0000                0,9        0     9178 anon_inode

Adding to @liberforce answer, if the process is already running you can get the file name using lsof

form strace

[pid  7529] read(102, 0x7fedc64c2fd0, 16) = -1 EAGAIN (Resource temporarily unavailable)

Now, with lsof

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