linuxunixfile-descriptor

Determine if two fds are duplicates?


Preferably portably, but at least under Linux, is there a way to determine if two file descriptors are duplicates referring to the same open file description?


Solution

  • On Linux 5.12, you can use the kcmp syscall with KCMP_FILE to determine if two file descriptors refer to the same open file description.