|
|
Subscribe / Log in / New account

Grabbing file descriptors with pidfd_getfd()

Grabbing file descriptors with pidfd_getfd()

Posted Jan 14, 2020 14:52 UTC (Tue) by dona73110 (guest, #113155)
Parent article: Grabbing file descriptors with pidfd_getfd()

>One thing that is possible in current kernels is to open a file that another process also has open; the information needed to do that is in each process's /proc directory. That does not work, though, for file descriptors referring to pipes, sockets, or other objects that do not appear in the filesystem hierarchy.

You sure can open a pipe that another process has open, by opening /proc/PID/fd/FD ... open(2) opens the actual files that these symlinks represent, which in the case of deleted files or pipes, etc, do not correspond to the path in the symlink target returned by readlink.


to post comments

Grabbing file descriptors with pidfd_getfd()

Posted Jan 29, 2020 1:35 UTC (Wed) by cyphar (subscriber, #110703) [Link]

You're right about how magic-links work (and re-opening through /proc/$pid/fd does work for pipes), but this does not work for sockets or anonfds -- you'll get -ENXIO when you try to re-open them. Additionally, there is still a pid recycling race condition if you use procfs (unless you have a first-generation /proc/$pid-style pidfd).


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds