> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/4.3-bsd-unix-cao-zuo-xi-tong-she-ji-yu-shi-xian/di-yi-bu-fen-gai-lan/2.10.-jin-cheng-jian-tong-xin.md).

# 2.10 进程间通信

4.3BSD 的进程间通信按通信域（communication domain）组织。当前支持的域包括：UNIX 域，用于同一台机器上执行的进程之间的通信；Internet 域（internet domain），用于使用 TCP/IP 协议套件（也许在 DARPA Internet 或 NSFnet 之内）的进程之间的通信；XNS 域（XNS domain），用于使用施乐网络系统（XNS）协议的进程之间的通信。

在一个域内，通信发生在称为套接字（socket）的通信端点之间。如 2.6 节所述，`socket` 系统调用创建套接字并返回一个描述符；其他 IPC 系统调用见第 10 章。每个套接字都有一个类型，规定其通信语义，包括可靠性、保序和不重复等性质。

每个套接字都关联一个通信协议（communication protocol）。协议提供套接字类型所要求的语义。应用程序创建套接字时可以请求特定协议，也可以让系统为所建套接字的类型选择一个合适的协议。

套接字可以绑定地址。套接字地址的形式和含义取决于创建套接字的通信域。在 UNIX 域中把名字绑定到套接字，会在文件系统中创建一个文件。

通过套接字收发的普通数据不带类型。数据表示问题由构建在进程间通信设施之上的库负责。除普通数据外，通信域还可以支持一种特别类型的数据的收发，称为访问权（access rights）。例如 UNIX 域用这一设施在进程之间传递描述符。

4.2BSD 之前，UNIX 上的网络实现通常靠重载字符设备接口来实现。套接字接口的一个目标是：让朴素的程序不加修改就能在流式连接上工作。这样的程序只有在 `read` 和 `write` 系统调用保持不变时才能工作。因此原有接口原封不动地保留下来，并使其作用于流式套接字；为更复杂的套接字（比如用来发送数据报、每次 `send` 调用都必须给出目的地址的那些）添加了新接口。

新接口的另一个好处是高度可移植。伯克利的测试发行版出来后不久，套接字接口就被一家 UNIX 厂商移植到了 System III（尽管 AT\&T 从未采用套接字接口或其实现，而是决定使用第八版的流机制）。Excelan 和 Interlan 等厂商还把套接字接口移植到许多以太网板上运行，这些厂商面向 PC 市场——那里的机器太小，无法在主处理器上运行网络。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://book.bsdcn.org/4.3-bsd-unix-cao-zuo-xi-tong-she-ji-yu-shi-xian/di-yi-bu-fen-gai-lan/2.10.-jin-cheng-jian-tong-xin.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
