linux - openpty() 是做什么的? "the openpty() function finds an available pseudoterminal"是什么意思?

标签 linux unix terminal pty

我觉得问这个(“只是 RTFM!”)很傻,但我无法理解这个手册页。 man page blurb描述openpty():

The openpty() function finds an available pseudoterminal and returns file descriptors for the master and slave in amaster and aslave. If name is not NULL, the filename of the slave is returned in name. If termp is not NULL, the terminal parameters of the slave will be set to the values in termp. If winp is not NULL, the window size of the slave will be set to the values in winp.

这是什么意思?

我的猜测是 openpty() 试图找到一个伪终端对应于进程树中更高层的终端仿真器(某个第 nth-parent,即程序正在运行的终端仿真器)在,如果有的话)。然而,文档让它听起来像 openpty() 只是任意地从 /dev/pts 中抓取一些东西。

另外,这里的“可用”是什么意思?似乎“可用”在伪终端的上下文中有多重含义(例如,内核会让终端仿真器创建一个伪终端,一个伪终端可以被读/写)。

最佳答案

However, the docs make it sound like openpty() just arbitrarily grabs something out of /dev/pts.

就是这样。

Also, what does "available" mean here? It seems like "available" has multiple meanings in the context of pseudoterminals (e.g. the kernel will let a terminal emulator create a pseudoterminal, a pseudoterminal can be read/written).

可用仅表示当前未被其他进程使用

The openpty() function finds an available pseudoterminal and returns file descriptors for the master and slave in amaster and aslave. If name is not NULL, the filename of the slave is returned in name. If termp is not NULL, the terminal parameters of the slave will be set to the values in termp. If winp is not NULL, the window size of the slave will be set to the values in winp.

这是什么意思?

作为返回,您将收到操作伪术语、其从属部分、主控部分及其文件名所需的所有数据。

伪术语通过实现终端输入/输出语义来模拟真实终端。它们在许多情况下使用,以模拟连接的终端(例如,想想当您通过 ssh 登录到远程系统时会发生什么)或控制某些交互式程序(例如,设计一个 shell 必须在其中运行的 GUI 终端) ).

I feel silly asking this ("just RTFM!")

当然不是那种情况,终端和 session 管理是非常棘手的事情,一开始很难处理。

-----编辑-----

真实终端。它以前如何?在早期(不是很早,恐龙世界更可怕)连接到我们使用终端的系统,一个带有键盘的简单设备,一个屏幕(没有图形)和一些小的硬件和软件来管理一条线被插入其中一台电脑的插头。因此,在操作系统中需要管理来自终端的所有这些输入/输出:在需要时将键入的字符回显到屏幕,缓冲输入/输出以便能够删除命令行上的字符等。该操作系统部分是通过管理的终端驱动程序表示为类似 /dev/ttyXXX 的设备。一台这样的物理设备,一台OS终端设备。

现在这样的物理设备已经不存在了,除了在一些特殊情况下,比如服务器控制台(我的意思是直接连接到机器的那个!,或者当所有这些奇怪的消息以文本模式出现时你的屏幕在启动时, ETC)。我们现在通过许多不同的虚拟事物连接到操作系统(当今的计算机世界是关于虚拟的),例如模拟物理终端行为的 GUI 终端。然后,旧物理线路的两端部分在一个伪终端中表示,伪终端分为两部分:主站和从站。 slave 代表应用程序看到的操作系统中的旧部分。 master 代表旧物理线路的插头,因此它现在作为软件提供,让您编写一个能够对该虚拟线路<进行输入/输出控制的应用程序/em> 并且表现得像一个真正的终端

关于linux - openpty() 是做什么的? "the openpty() function finds an available pseudoterminal"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47806759/

相关文章:

c++ - 在 linux 中创建 "virtual"OpenGL 上下文

c# - System.IO.Path 或与 Unix 路径等效使用

linux - 递归覆盖bash中的rc文件

ubuntu - 如何在 Ubuntu 中正确显示字符

linux - 仅在特定列中考虑公共(public)值的命令行

visual-studio-code - 当 Zshell 主题存在时,终端开始表现不佳

c - Linux服务器--用鼠标选择任何内容后$后面出现 "^C"

python - 字符串格式python

linux - 无法在 Ambari Hadoop 集群上启动 HUE

c - readdir 为目录返回 d_type == DT_UNKNOWN 的 dirent。和