Seamless file descriptor transfer between processes with pidfd and pidfd_getfd

A Primer on Processes

A running instance of a program is called a process. Processes are referred to using a process ID (pid), which is an arbitrary number chosen by the kernel, usually limited to 32768, but on some distros, the max limit is 2²². The init system (launchd on MacOS, systemd on some of the more recent Linux distros) is assigned pid 1.

The Problem with PIDs

One of the problems with process IDs has been the fact that they aren’t unique.

What is pidfd?

Unlike process ID which is any random integer assigned by the kernel, a pidfd is a persistent file descriptor that refers to another process. As with all file descriptors, pidfds are private to the process that has requested for the file descriptor.


So, a process can get a file descriptor referring to another process with the pidfd_open system call. But this won’t help solve the file descriptor transfer problem, where one process can transfer/send its file descriptors over to another proceess.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cindy Sridharan

Cindy Sridharan

@copyconstruct on Twitter. views expressed on this blog are solely mine, not those of present or past employers.