什么是插座?是一个过程吗?

what is a socket? Is it a process?

我正在研究 os 概念,我发现套接字是通信的终点。现在究竟什么是套接字?它是系统通信的过程吗? 提前致谢

通过阅读维基百科文章,我明白了为什么您可能会感到困惑。

套接字是一个虚拟设备。也就是说,它是一种用软件编写的设备,没有物理设备。因此,您可以像对终端所做的那样从套接字读取和写入。

套接字成对工作以进行通信,通常是双向的。读取套接字 (A) 并写入套接字 (B) --- 或 ---- 写入套接字 (A) 并从套接字读取 --- 或 --- 来回切换。

套接字一般用于网络通信。它们通常可以支持多种协议(TPC/IP、UDP/IP,甚至是 DECnet——范围取决于底层系统)。

套接字也可用于单个系统上的进程间通信。

大多数 c 系列语言及其基础语言将套接字实现为 Berkeley sockets which are implemented as file descriptors。来自维基百科:

In the traditional implementation of Unix, file descriptors index into a per-process file descriptor table maintained by the kernel, that in turn indexes into a system-wide table of files opened by all processes, called the file table. This table records the mode with which the file (or other resource) has been opened: for reading, writing, appending, and possibly other modes. It also indexes into a third table called the inode table that describes the actual underlying files.[3] To perform input or output, the process passes the file descriptor to the kernel through a system call, and the kernel will access the file on behalf of the process. The process does not have direct access to the file or inode tables.

所以在高层次上,套接字被实现为文件,其文件描述符或句柄被引用为套接字的标识符。