0

I am using the Linux sendmsg() function to send a file-descriptor to another process over a Unix Socket along with some data payload. I make multiple calls to sendmsg. In the recvmsg() companion call inside the destination process, I get the file descriptor using something like "fdptr = (int *) CMSG_DATA(cmsg); memcpy(fdptr, myfds, NUM_FD * sizeof(int));" What I am noticing that each time I look at the file descriptor, the file descriptor is yet a DIFFERENT number than it was in the prior recvmsg() call.

My question: Is the destination process holding open a bunch of open descriptors to the same file/hardware?? Do I need to close the descriptors?

What would happen if I was not to try to copy the descriptor with "memcpy(fdptr, myfds, NUM_FD * sizeof(int));" and essentially 'left it inside' CMSG_DATA(cmsg)? Would there be some descriptor with an unknown number sitting out there? Had I not copied it out, I would have never seen it was essentially yet another descriptor number.

westocl
  • 73
  • 6
  • Read about the difference between "file descriptor" and "open file description", e.g. in [open(2)](http://man7.org/linux/man-pages/man2/open.2.html). – o11c Oct 22 '19 at 22:00
  • `sendmsg` + `recvmsg` is basically the same as `dup`, but (potentially) between different processes. – o11c Oct 22 '19 at 22:01

0 Answers0