开发者

Identifying file causing hang from strace

开发者 https://www.devze.com 2023-02-14 16:15 出处:网络
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:

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


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


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消