pty 和 tty 是什么意思?

发布于 2024-10-07 10:48:26 字数 84 浏览 0 评论 0 原文

我注意到在一些开源项目中很多提到ptytty,有人可以告诉我它们是什么意思以及它们之间有什么区别吗?

I noticed many mentions of pty and tty in some open source projects, could someone tell me what do they mean and what is the difference between them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

孤独陪着我 2024-10-14 10:48:26

tty 最初表示“teletype”“pty” 表示“伪teletype”

在 UNIX 中,/dev/tty* 是任何类似于“电传打字机”的设备,即:终端。 (之所以称为电传打字机,是因为在那些黑暗的日子里,我们的终端就是这样的。)

pty 是一个pseudotty,一个设备条目,其作用类似于进程读写的终端在那里,但由其他东西管理。它们首先出现(我记得)用于 X Window 和 screen 等,您需要一些像终端但可以从另一个程序使用的东西。

tty originally meant "teletype" and "pty" means "pseudo-teletype".

In UNIX, /dev/tty* is any device that acts like a "teletype", i.e: a terminal. (Called teletype because that's what we had for terminals in those benighted days.)

A pty is a pseudotty, a device entry that acts like a terminal to the process reading and writing there, but is managed by something else. They first appeared (as I recall) for X Window and screen and the like, where you needed something that acted like a terminal but could be used from another program.

活雷疯 2024-10-14 10:48:26

tty 是一个终端(它代表teletype - 原始终端使用行式打印机进行输出,使用键盘进行输入!)。终端基本上只是一个使用文本进行输入和输出的用户界面设备。

pty 是一个伪终端 - 它是一种软件实现,对于附加程序来说就像终端一样,但它不是直接与“真实”终端通信,而是传输另一个程序的输入和输出。

例如,当您 ssh 到计算机并运行 ls 时,ls 命令会将其输出发送到伪终端,该伪终端的另一端连接到SSH 守护进程。

A tty is a terminal (it stands for teletype - the original terminals used a line printer for output and a keyboard for input!). A terminal is a basically just a user interface device that uses text for input and output.

A pty is a pseudo-terminal - it's a software implementation that appears to the attached program like a terminal, but instead of communicating directly with a "real" terminal, it transfers the input and output to another program.

For example, when you ssh in to a machine and run ls, the ls command is sending its output to a pseudo-terminal, the other side of which is attached to the SSH daemon.

白衬杉格子梦 2024-10-14 10:48:26

tty:电传打字机。通常指计算机上连接终端的串行端口。

pty:伪电传打字机。内核提供伪串行端口连接到模拟终端的程序,例如 xterm 或 screen。

tty: teletype. Usually refers to the serial ports of a computer, to which terminals were attached.

pty: pseudoteletype. Kernel provided pseudoserial port connected to programs emulating terminals, such as xterm, or screen.

暮年慕年 2024-10-14 10:48:26

如果运行不带命令行参数的 mount 命令(该命令会显示系统上安装的文件系统),您会注意到类似如下的一行:

none on /dev/pts type devpts (rw,gid=5,mode=620)

这表明一种特殊类型的文件系统 devpts 已安装在/dev/pts。这个文件系统不与任何硬件设备关联,是由 Linux 内核创建的“神奇”文件系统。它类似于 /proc 文件系统

/dev 目录一样,/dev/pts 包含与设备对应的条目。但与普通目录 /dev 不同,/dev/pts 是由 Linux 内核动态创建的特殊目录。目录内容随时间变化
并反映系统运行状态。
/dev/pts 中的条目对应于伪终端(或伪 TTY、PTY)。

Linux 为您打开的每个新终端窗口创建一个 PTY,并在 /dev/pts 中显示相应的条目。 PTY 设备的作用类似于终端设备 - 它接受来自键盘的输入并显示其中运行的程序的文本输出。 PTY 是有编号的,PTY 编号是对应条目的名称
/dev/pts

例如,如果新终端窗口的 PTY 编号为 7,则从另一个窗口调用此命令:

echo ‘I am a virtual di ’ > /dev/pts/7

输出将显示在新终端窗口中。
您可以尝试将 7 交换为另一个数字,并且根据打开的终端给出的数字,您将在另一个终端窗口上看到输出。 /dev/pts 是执行此操作的公共汽车(邮局)!

If you run the mount command with no command-line arguments, which displays the file systems mounted on your system, you’ll notice a line that looks something like this:

none on /dev/pts type devpts (rw,gid=5,mode=620)

This indicates that a special type of file system, devpts, is mounted at /dev/pts. This file system, which isn’t associated with any hardware device, is a “magic” file system that is created by the Linux kernel. It’s similar to the /proc file system

Like the /dev directory, /dev/pts contains entries corresponding to devices. But unlike /dev , which is an ordinary directory, /dev/pts is a special directory that is created dynamically by the Linux kernel. The contents of the directory vary with time
and reflect the state of the running system.
The entries in /dev/pts correspond to pseudo-terminals (or pseudo-TTYs, or PTYs).

Linux creates a PTY for every new terminal window you open and displays a corresponding entry in /dev/pts. The PTY device acts like a terminal device - it accepts input from the keyboard and displays text output from the programs that run in it. PTYs are numbered, and the PTY number is the name of the corresponding entry in
/dev/pts.

For example, if the new terminal window’s PTY number is 7, invoke this command from another window:

echo ‘I am a virtual di ’ > /dev/pts/7

The output appears in the new terminal window.
You can try to exchange the 7 for another number, and, depending on the numbers given to your open terminals, you will see the output on another terminal window. /dev/pts is the bus (the post office) to do this!

虚拟世界 2024-10-14 10:48:26

tty 是一个物理 t终端-telety< /strong>计算机上的pe端口(通常是串行端口)。

Teletype tty 也可以由作为内核空间中的模块运行的计算机程序来模拟。

teletype这个词是电报打字机的缩写,或者电传打字机设备 - 本身就是电报机的替代品< /a> 1830 年代和 1840 年代的编码机。

电传打字机
TTY - 1930 年代的电传打字机

pty 是一个 pseudo-t计算机操作系统内核提供的电子端口,用于连接用户登陆终端仿真软件程序,例如 ssh、xterm 或 screen。

输入图像描述这里
 PTY - PseudoTeletype

终端只是使用文本进行输入和输出的计算机用户界面。

操作系统实现

这些使用pteletype端口,但是它们的命名和实现略有不同。

Linux/dev 上安装一个特殊的文件系统 devpts('s' 可能代表 serial)为您打开的每个新终端窗口在 /dev/pts 中创建相应的条目,例如 /dev/pts/0

ma​​cOS/FreeBSD 也可以使用/dev 文件结构但是,它们对您打开的每个新终端窗口使用编号的 TTY 命名约定 ttys例如 /dev/ttys002

Microsoft Windows 仍然具有用于在其命令外壳内用于输出到打印机的行式打印机终端的 LPT 端口的概念。

A tty is a physical terminal-teletype port on a computer (usually a serial port).

A Teletype tty can also be emulated by a computer program running as a module in kernel space.

The word teletype is a shorting of the telegraph typewriter, or teletypewriter device from the 1930s - itself a replacement for the telegraph encoding machines of the 1830s and 1840s.

Teletypewriter
TTY - Teletypewriter 1930s

A pty is a pseudo-teletype port provided by a computer Operating System Kernel to connect user land terminal emulation software programs such as ssh, xterm, or screen.

enter image description here
 PTY - PseudoTeletype

A terminal is simply a computer's user interface that uses text for input and output.

OS Implementations

These use pseudo-teletype ports however, their naming and implementations have diverged a little.

Linux mounts a special file system devpts on /dev (the 's' presumably standing for serial) that creates a corresponding entry in /dev/pts for every new terminal window you open, e.g. /dev/pts/0

macOS/FreeBSD also use the /dev file structure however, they use a numbered TTY naming convention ttys for every new terminal window you open e.g. /dev/ttys002

Microsoft Windows still has the concept of an LPT port for Line Printer Terminals within it's Command Shell for output to a printer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文