在<<The Linux Programming Interface>>书中的61.13.2小节,有这样的描述:
The sendmsg() system call can do everything that is done by write(), send(), andsendto(); the recvmsg() system call can do everything that is done by read(),recv(), and recvfrom(). In addition, it also can perform scatter-gather I/O and transmit ancillary data (also known as control information).
这里说的意思是sendmsg/recvmsg除了能够进行正常的数据发送之外,还能够用来传递ancillary data数据。这里所说的ancillary data包括两类信息:file descriptor和sender credential。这里我们关注file descriptor,因为credential与之类似。
为了传递file descriptor,需要使用UNIX domain socket(可以为TDP,也可以是UDP)。使用UNIX domain socket就限定file descriptor仅仅在同一个host上有效,从机器A传递进程Pa的fd到机器B的进程Pb,显然不能使用。Why?UNIX-like机器上的文件索引结构如下: