Skip to main content
added 6 characters in body
Source Link

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:

ls /proc/$parent_pid/task/$task/fd and ls /proc/$parent_process/fd

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.

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:

/proc/$parent_pid/task/$task/fd and /proc/$parent_process/fd

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.

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:

ls /proc/$parent_pid/task/$task/fd and ls /proc/$parent_process/fd

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.

Source Link

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:

/proc/$parent_pid/task/$task/fd and /proc/$parent_process/fd

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.