Article 4TSGQ Determine (from userspace) if two processes share the same struct file

Determine (from userspace) if two processes share the same struct file

by
reberhardt
from LinuxQuestions.org on (#4TSGQ)
Hi,

I'm working on building a tool that helps new systems programmers understand what file-related syscalls do. When a program hits a breakpoint, I want to generate some diagrams of the file descriptor tables, open file table, and vnode table for the running processes. I can get a lot of the info I need from /proc/*/fd and from lsof, but I can't tell when two file descriptors are referring to the *same* open file (e.g. they share the same cursor).

As a concrete example, say process A opens a file, then forks, producing process B. I can tell that both processes are referring the same file, but I can't tell whether file A and file B opened that file independently, or if they have the same underlying open file.

Reading through https://www.tldp.org/LDP/lki/lki-3.html, I understand what I need is to determine when two tasks share a particular `struct file`. However, I don't know if this data is exposed through any API to user space. Is there something I can look at to determine this? I'm guessing the answer is no, since `struct file` doesn't include anything like a unique ID, but I just want to make sure before I try doing something unnecessarily complicated.

Thanks!
Ryanlatest?d=yIl2AUoC8zA latest?i=ifh3eVa5SjE:fdKN5bhE87M:F7zBnMy latest?i=ifh3eVa5SjE:fdKN5bhE87M:V_sGLiP latest?d=qj6IDK7rITs latest?i=ifh3eVa5SjE:fdKN5bhE87M:gIN9vFwifh3eVa5SjE
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments