The linux ancillary data can be used to share file descriptors across multiple processes in unix over unix domain sockets. The application has 2 processes A & B listening for data on the network, and upon receiving new connection the recipient process (either A or B) accepts the connection. Now support process A accepts the connection, in order to share this new socket descriptor with process B, process A sends ancillary data to process B. This is all fine and ok.
See section 17.4 in “Advanced Programming in the UNIX Environment” for some good information about file descriptor passing (and a nice picture!). In particular:
Technically, we are passing a pointer to an open file table entry from one process to another. This pointer is assigned the first available descriptor in the receiving process. (Saying that we are passing an open descriptor mistakenly gives the impression that the descriptor number in the receiving process is the same as in the sending process, which usually isn't true.)
So when passing a file descriptor from process A to process B, the descriptor numbers can be different. Also process B does not have any information about the descriptor number used in process A.
There is no "built-in" mechanism to pass the information about closing a file descriptor from B back to A. You will need to send a custom message for that purpose.