Passing file descriptor

本文介绍了UNIX域套接字如何用于传递文件描述符,详细阐述了sendmsg/recvmsg系统调用在这一过程中的作用,以及内核如何在发送方和接收方之间安全地复制文件描述符,确保在同一主机上的有效传递。
摘要由CSDN通过智能技术生成

在<<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机器上的文件索引结构如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值