识别导致 strace 挂起的文件
我有一个在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过调用
strace -o log -eopen,read yourprogram
来查找哪个文件使用该文件描述符。然后在log
文件中搜索对感兴趣的read
的调用。从这一行(而不是从文件的第一行)开始,向上搜索此文件描述符的第一次出现(通过调用open
返回)。例如这里,
open
返回的文件描述符是3:You can find which file uses this file descriptor by calling
strace -o log -eopen,read yourprogram
. Then search in thelog
file the call toread
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 toopen
).For example here, the file descriptor returned by
open
is 3: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 forread()
.添加到 @liberforce 答案,如果进程已经在运行,您可以使用 lsof
形式 strace
现在使用 lsof获取文件名
Adding to @liberforce answer, if the process is already running you can get the file name using lsof
form strace
Now, with lsof