How to display open file descriptors with thread id without using
I know a similar question exists but the answer doesn't include thread details.
On top of the answers given, it is perhaps worth mentioning that in Linux, all threads started by a process, typically share the same set of file descriptors. Thus, both:
would typically produce the same output, which implies that child processes inherit the file descriptors referenced by their parent. The 'lsof' manual actually specifies that too under the -K option documentation:
"In general threads and tasks inherit the files of the caller, but may close some and open others, so lsof always reports all the open files of threads and tasks."
So to eliminate any potential ambiguity (perhaps created by the previous answers), listing
/proc/$parent_pid/$task/fd does not guerantee that $task was the thread that refrences the file descriptor ids in that directory. If you need a reliable way of telling which thread opened a particular file descriptor, you can
strace the program to track system calls like
open(), that require the kernel to assign a file descriptor.