第 137 / 187 篇

13.4. 进程间通信

说明

本文是个人学习用的非官方中英对照译文,原文:https://diveintosystems.org/book/C13-OS/ipc.html。
原书采用 CC BY-NC-ND 4.0 许可(禁止演绎),请勿公开传播本译文。
标为「译注」「现代更新」的内容是译者补充,不代表原书作者观点;代码与原文逐字一致,未作改动。

13.4. Interprocess Communication

进程是操作系统实现的主要抽象之一。私有的虚拟地址空间是多道程序设计系统中的一个重要抽象,也是操作系统防止进程干扰彼此执行状态的方式之一。然而,有时用户或程序员可能希望自己的应用进程在运行时能够相互通信(或者共享一部分执行状态)。

Processes are one of the primary abstractions implemented by the OS. Private virtual address spaces are an important abstraction in multiprogrammed systems, and are one way in which the OS prevents processes from interfering with one another’s execution state. However, sometimes a user or programmer may want their application processes to communicate with one another (or to share some of their execution state) as they run.

操作系统通常支持几种进程间通信(interprocess communication,IPC)方式,即进程之间相互通信或共享执行状态的方式。信号(signal)是一种非常受限的进程间通信形式,一个进程可以通过它向另一个进程发送信号,通知其发生了某个事件。进程还可以通过消息传递(message passing)进行通信,操作系统为此实现了一种消息通信信道的抽象,进程用它与另一个进程交换消息。最后,操作系统还可能通过共享内存(shared memory)支持进程间通信,允许一个进程与其他进程共享其全部或部分虚拟地址空间。拥有共享内存的进程可以通过读写共享空间中的地址来相互通信。

Operating systems typically implement support for several types of interprocess communication, or ways in which processes can communicate or share their execution state. Signals are a very restricted form of interprocess communication by which one process can send a signal to another process to notify it of some event. Processes can also communicate using message passing, in which the OS implements an abstraction of a message communication channel that is used by a process to exchange messages with another process. Finally, the OS may support interprocess communication through shared memory that allows a process to share all or part of its virtual address space with other processes. Processes with shared memory can read or write to addresses in shared space to communicate with one another.