Identifying file causing hang from strace

Greg picture Greg · Mar 4, 2011 · Viewed 7.5k times · Source

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

Answer

liberforce picture liberforce · Mar 7, 2011

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