The procfs will tell me which fds a process is using at any given time. But is there a way to determine which are open for reading vs. writing?
In the output below, clearly the process owner (user 'x') has read/write access to the link/file, but this isn't the same as knowing whether pid 4166 is writing to or reading from a particular fd.
$ ls -l /proc/4166/fd/ total 0 lrwx------ 1 x x 64 Mar 12 21:15 0 -> /dev/pts/3 lrwx------ 1 x x 64 Mar 12 21:15 1 -> /dev/pts/3 lrwx------ 1 x x 64 Mar 12 21:15 2 -> /dev/pts/3 lrwx------ 1 x x 64 Mar 12 21:15 255 -> /dev/pts/3
I know that the lsof utility can do this:
$ lsof -p 4166 | grep CHR bash 4166 x 0u CHR 136,3 0t0 6 /dev/pts/3 bash 4166 x 1u CHR 136,3 0t0 6 /dev/pts/3 bash 4166 x 2u CHR 136,3 0t0 6 /dev/pts/3 bash 4166 x 255u CHR 136,3 0t0 6 /dev/pts/3
The manpage for lsof says that for example those trailing u's behind the fd numbers (0, 1, 2, 255) mean that the fd is open for reading and writing.
My question though is whether or not it's possible to obtain this information via the procfs rather than lsof. For various reasons, executing lsof inside of another programming language is less convenient for me than polling procfs, so I'm wondering if there's a direct way to do it there.