C语言 pty 和 tty 是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4426280/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 07:22:37  来源:igfitidea点击:

What do pty and tty mean?

cunixnetworkingttyvocabulary

提问by why

I noticed there are many mentions of ptyand ttyin some opensource projects, could someone can tell me what do they mean and what is the difference between them? Thanks!

我注意到有很多提到的ptytty一些开源项目,可能有人能告诉我做他们的意思和它们之间有什么区别呢?谢谢!

采纳答案by Charlie Martin

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

“tty”最初的意思是“电传打字机”,“pty”的意思是“伪电传打字机”。

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

在 UNIX 中,/dev/tty* 是任何充当“电传打字机”的设备,即终端。(称为电传打字机,因为那是我们在那些黑暗日子里用于终端的东西。)

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.

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

回答by caf

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.

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

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.

pty 是一个伪终端——它是一个软件实现,在附加的程序中看起来像一个终端,但它不是直接与“真实”终端通信,而是将输入和输出传输到另一个程序。

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

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

回答by wnoise

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

tty:电传打字机。通常是指计算机的串行端口,终端连接到这些端口。

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

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

回答by nikolaos_mparoutis

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

如果您运行不带命令行参数的 mount 命令,它会显示您系统上安装的文件系统,您会注意到一行看起来像这样:none on /dev/pts type devpts (rw,gid=5, mode=620) 这表明一个特殊类型的文件系统 devpts 挂载在 /dev/pts 。这个文件系统与任何硬件设备无关,是一个“神奇”的文件系统,由Linux内核。它类似于 /proc 文件系统

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 cre- ated 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).

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

Linux creates a PTY for every new terminal window you open and displays a corre- sponding 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 .

Linux 为你打开的每个新终端窗口创建一个 PTY 并在 /dev/pts 中显示一个相应的条目。 PTY 设备就像一个终端设备——它接受来自键盘的输入并显示来自其中运行的程序的文本输出. PTY 是编号的,PTY 编号是 /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.

例如,如果新终端窗口的 PTY 编号为 7,则从另一个窗口调用此命令: % echo 'I am a virtual di ' > /dev/pts/7 输出出现在新终端窗口中。

回答by Tony Barganski

A ttyis a physicalterminal-teletype port on a computer (usually a serial port).

tty是一个物理erminal-ELET ýPE的计算机(通常是一个串行端口)上的端口。

The word teletypeis a shorting of the telegraph typewriter, or teletypewriterdevice from the 1930s - itself an electromagnetic device which replaced the telegraphencoding machines of the 1830s and 1840s.

电传打字机一词是1930 年代电报打字机电传打字机设备的缩写,它本身是一种电磁设备,取代了 1830 和 1840 年代的电报编码机。

Teletypewriter
TTY - Teletypewriter 1930s

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

A ptyis a pseudo-teletype port provided by a computer Operating System Kernel to connect software programs emulating terminals, such as ssh, xterm, or screen.

ptypseudo-ELE TY由计算机操作系统内核提供了用于连接的软件程序模拟终端,如ssh,xterm的,或屏幕PE端口。

enter image description here
PTY - PseudoTeletype

在此处输入图片说明
PTY - 伪电传打字机

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.

这些用pseudo-牛逼ELE TYPE口然而,它们的命名和实现有分歧一点。

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

Linux的安装一个特殊的文件系统devpts的/ dev(的“s”大概站立小号erial)创建一个对应的条目/dev/pts为你打开每一个新的终端窗口,如/dev/pts/0


macOS/FreeBSDalso use the /devfile structure however, they use a numbered TTYnaming convention ttysfor every new terminal window you open e.g. /dev/ttys002


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


Microsoft Windowsstill has the concept of an LPTport for Line Printer Terminals within it's Command Shell for output to a printer.


Microsoft WindowsLPT在它的命令外壳中仍然有行式打印机终端端口的概念,用于输出到打印机。