初识Unix Domain socket

本文深入探讨Unix域套接字的性质,解释它们如何作为进程间通信的工具,并通过实际代码示例展示其用法。同时,强调了代码在揭示真相方面的优势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

       佛曰: 并非所有的socket都用于网络通信。


       我说过,英语描述东西就是准确, 所以,还是看看维基百科怎么说吧:

Unix domain socket or IPC socket (inter-process communication socket) is a data communications endpoint for exchanging data between processes executing within the same host operating system. While similar in functionality tonamed pipes, Unix domain sockets may be created as connection‑mode (SOCK_STREAM or SOCK_SEQPACKET) or as connectionless (SOCK_DGRAM), while pipes are streams only. Processes using Unix domain sockets do not need to share a common ancestry. The API for Unix domain sockets is similar to that of an Internet socket, but it does not use an underlying network protocol for communication. The Unix domain socket facility is a standard component ofPOSIX operating systems.

Unix domain sockets use the file system as their address name space. They are referenced by processes as inodes in the file system. This allows two processes to open the same socket in order to communicate. However, communication occurs entirely within the operating system kernel.

In addition to sending data, processes may send file descriptors across a Unix domain socket connection using thesendmsg() and recvmsg() system calls.


      我喜欢代码,很多时候, 有这么一种感觉, 没有代码就没有真相。 一段可运行的代码例子,胜过很多无聊的讲解。我家里暂时没有unix/linux环境, 所以就没有代码分享, 在后续博文中,我会转载一些相关的文章,一起学习。


      


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值