Linux 上 TTY 的起源

注:机翻,未校对。


What is a TTY on Linux? (and How to Use the tty Command)

img
What does the tty command do? It prints the name of the terminal you’re using. TTY stands for “teletypewriter.” What’s the story behind the name of the command? That takes a bit more explaining.
tty 命令有什么作用?它会打印您正在使用的终端的名称。TTY 代表 “电传打字机”。命令名称背后的故事是什么?这需要更多的解释。

Teleprinters From the 1800s

1800 年代的电传打印机

In the 1830s and 1840s, machines known as teleprinters were developed. These machines could send typed messages “down the wire” to distant locations. The messages were typed by the sender on a keyboard of sorts. They were printed on paper at the receiving end. They were an evolutionary step in telegraphy, which had previously relied on Morse and similar codes.
在 1830 年代和 1840 年代,开发了称为电传打印机的机器。这些机器可以将键入的消息 “向下” 发送到遥远的地方。这些消息是由发件人在某种键盘上键入的。它们在接收端打印在纸上。它们是电报的进化步骤,以前电报依赖于摩尔斯电码和类似的电码。

Messages were encoded and transmitted, then received, decoded, and printed. There were several techniques used to encode and decode the messages. The most famous, and one of the most prolific, was patented in 1874 by Émile Baudot, for whom the baud rate is named. His character encoding scheme pre-dated ASCII by 89 years.
对消息进行编码和传输,然后接收、解码和打印。有几种技术用于编码和解码消息。最著名也是最多产的专利之一,于 1874 年由 Émile Baudot 获得专利,波特率就是以他的名字命名的。他的字符编码方案比 ASCII 早 89 年。

Baudot’s encoding eventually became the closest thing to a standard in teleprinter encoding, and it was adopted by most manufacturers. Baudot’s original hardware design had only five keys, similar to piano keys. The operator was required to learn a particular key combination for each letter. Eventually, the Baudot encoding system was coupled to a traditional keyboard layout.
Baudot 的编码最终成为最接近电传打印机编码标准的东西,并被大多数制造商采用。Baudot 最初的硬件设计只有五个键,类似于钢琴键。操作员需要学习每个字母的特定组合键。最终,Baudot 编码系统与传统的键盘布局相结合。

To mark that advancement, the machines were named teletypewriters. This was shortened to teletypes and eventually to TTYs. So that’s where we get the acronym TTY from, but what has telegraphy got to do with computing?
为了纪念这一进步,这些机器被命名为电传打字机。这被缩短为电传打字机,并最终被缩短为 TTY。这就是我们得到首字母缩略词 TTY 的地方,但电报与计算有什么关系?

ASCII and Telex

ASCII 和电传

When ASCII arrived in 1963, it was adopted by the teletype manufacturers. Despite the invention and widespread use of the telephone, teletypes were still going strong.
当 ASCII 于 1963 年问世时,它被电传打字机制造商采用。尽管电话已经发明并被广泛使用,但电传打字机仍然很强大。

Telex was a worldwide network of teletypes that allowed written messages to be sent around the globe. They were the principal means of transmitting written messages in the period following World War II up to the fax machine boom of the 1980s.
电传是一个全球性的电传打字机网络,允许在全球范围内发送书面信息。它们是二战后至 1980 年代传真机热潮期间传输书面信息的主要手段。

Computers were evolving too. They were becoming capable of interacting with users in real time, and of supporting multiple users. The old batch method of working became insufficient. People didn’t want to wait 24 hours or longer for their results. Making stacks of punched cards and waiting overnight for results was no longer acceptable.
计算机也在不断发展。它们能够与用户实时交互,并支持多个用户。旧的批处理工作方法变得不够用。人们不想等待 24 小时或更长时间才能获得结果。制作成堆的打孔卡片并等待一夜的结果不再是可以接受的。

People needed a device that would allow them to enter instructions and get results sent back to them. People wanted efficiency.
人们需要一种设备,允许他们输入指令并将结果发回给他们。人们想要效率。

The Teletype Repurposed

电传打字机的新用途

The teletype was the perfect candidate as an input/output device. It was, after all, a device designed to allow messages to be typed, encoded, sent, received, decoded, and printed.
电传打字机是输入 / 输出设备的完美候选者。毕竟,它是一种旨在允许输入、编码、发送、接收、解码和打印消息的设备。

What did the teletype care if the device at the other end of the connection wasn’t another teletype? As long as it spoke the same encoding language and could receive messages and send messages back, the teletype was happy.
如果连接另一端的设备不是另一个电传打字机,电传打字机在乎什么?只要它说相同的编码语言,并且可以接收消息并发送消息,电传打字机就很高兴。

And of course, it used a more-or-less standard keyboard.
当然,它或多或少使用了标准键盘。

Hardware Emulated Teletypes

硬件模拟电传打字机

Teletypes became the default means of interacting with the large mini and mainframe computers of that era.
电传打字机成为那个时代与大型迷你和大型计算机交互的默认方式。

They were eventually replaced by devices that emulated those electro-mechanical machines using electronics. These had Cathode Ray Tubes (CRTs) instead of paper rolls. They didn’t shake when delivering responses from the computer. They permitted hitherto impossible functionality, such as moving the cursor around the screen, clearing the screen, bolding text, and so on.
它们最终被使用电子设备模拟那些机电机器的设备所取代。这些具有阴极射线管 (CRT) 而不是纸卷。当从计算机发送响应时,它们不会摇晃。它们允许迄今为止不可能的功能,例如在屏幕上移动光标、清除屏幕、加粗文本等。

The DEC VT05 was an early example of a virtual teletype, and an ancestor of the famous DEC VT100. Millions of DEC VT100s were sold.
DEC VT05 是虚拟电传打字机的早期示例,也是著名的 DEC VT100 的祖先。售出数百万台 DEC VT100。

Software Emulated Teletypes

软件模拟电传打字机

In the desktop environment of Linux and other Unix-like operating systems such as macOS, the terminal window and applications such as x-term and Konsole are examples of virtual teletypes. But these are emulated entirely in software. They are called pseudo-teletypes. This was shortened to PTS.
在 Linux 和其他类 Unix 操作系统(如 macOS)的桌面环境中,终端窗口和 x-term 和 Konsole 等应用程序是虚拟电传打字机的示例。但这些完全是在软件中模拟的。它们被称为伪电传打字机。这被缩短为 PTS。

And that’s where tty comes in.
这就是 tty 的用武之地。

What can tty Tell us?

tty 能告诉我们什么?

In Linux, there is a pseudo-teletype multiplexor which handles the connections from all of the terminal window pseudo-teletypes (PTS). The multiplexor is the master, and the PTS are the slaves. The multiplexor is addressed by the kernel through the device file located at /dev/ptmx.
在 Linux 中,有一个伪电传打字多路复用器,它处理来自所有终端窗口伪电传打字机 (PTS) 的连接。多路复用器是主站,PTS 是从站。多路复用器由内核通过位于 /dev/ptmx 的设备文件进行寻址。

The tty command will print the name of the device file that your pseudo-teletype slave is using to interface to the master. And that, effectively, is the number of your terminal window.
tty 命令将打印伪电传打字从站用于连接主站的设备文件的名称。实际上,这就是您的终端窗口的编号。

Let’s see what tty reports for our terminal window:
让我们看看 tty 为我们的终端窗口报告了什么:

tty

tty in a terminal window

The response shows we are connected to the device file at /dev/pts/0.
响应显示我们已连接到位于 /dev/pts/0 的设备文件。

Our terminal window, which is a software emulation of a teletype (TTY), is interfaced to the pseudo-teletype multiplexor as a pseudo-teletype (PTS). And it happens to be number zero.
我们的终端窗口是电传打字机 (TTY) 的软件仿真,作为伪电传打字机 (PTS) 连接到伪电传打字机。它恰好是零号。

The Silent Option

静音选项

The -s (silent) option causes tty to generate no output.
-s(静默)选项会导致 tty 不生成输出。

tty -s

tty -s in a terminal window

It does is produce an exit value, however:
但是,它确实会产生一个退出值:

  • 0: if standard input is coming from a TTY device, emulated or physical.
    0:如果标准输入来自 TTY 设备,则为仿真设备或物理设备。
  • 1: if standard input is not coming from a TTY device.
    1:如果标准输入不是来自 TTY 设备。
  • 2: Syntax error, incorrect command line parameters were used.
    2:语法错误,使用了不正确的命令行参数。
  • 3: A write error has occurred.
    3:发生写入错误。

This is likely to be most useful in Bash scripting. But, even on the command line, we can demonstrate how to have a command executed only if you are running in a terminal window (a TTY or a PTS session).
这在 Bash 脚本中可能是最有用的。但是,即使在命令行上,我们也可以演示如何仅在终端窗口(TTY 或 PTS 会话)中运行时执行命令。

tty -s && echo "In a tty"

tty -s && echo "In a tty" in a terminal window

Because we are running in a TTY session, our exit code is 0, and the second command is executed.
因为我们在 TTY 会话中运行,所以我们的退出代码为 0,并执行第二个命令。

"In a tty" in a terminal window

The who Command who 命令

Other commands can reveal your TTY number. The who command will list information for all logged in users, including yourself.
其他命令可以显示您的 TTY 号码。who 命令将列出所有登录用户(包括您自己)的信息。

Alec and Mary are remotely connected to the Linux computer. They are connected to PTS one and two.
Alec 和 Mary 远程连接到 Linux 计算机。它们连接到 PTS 1 和 2。

User dave is shown as connected to “:0”.
用户 dave 显示为连接到 “:0”。

This represents the screen and keyboard physically connected to the computer. Even though the screen and keyboard are hardware devices, they are still connected to the multiplexor through a device file. tty reveals that it is /dev/pts/2.
这表示物理连接到计算机的屏幕和键盘。即使屏幕和键盘是硬件设备,它们仍然通过设备文件连接到多路复用器。tty 显示它是 /dev/pts/2。

who
tty

who and tty in a terminal window

Accessing a TTY

访问 TTY

You can access a full-screen TTY session by holding down the Ctrl+Alt keys, and pressing one of the function keys.
您可以通过按住 Ctrl+Alt 键并按其中一个功能键来访问全屏 TTY 会话。

Ctrl+Alt+F3 will bring up the login prompt of tty3.
Ctrl+Alt+F3 将显示 tty3 的登录提示。

tty3 console

If you log in and issue the tty command, you’ll see you are connected to /dev/tty3.
如果您登录并发出 tty 命令,您将看到您已连接到 /dev/tty3。

This isn’t a pseudo-teletype (emulated in software); it is a virtual teletype (emulated in hardware). It is using the screen and keyboard connected to your computer, to emulate a virtual teletype like the DEC VT100 used to do.
这不是伪电传打字机(在软件中模拟); 它是一种虚拟电传打字机(在硬件中模拟)。它使用连接到计算机的屏幕和键盘来模拟虚拟电传打字机,就像 DEC VT100 过去所做的那样。

You can use function keys Ctrl+Alt with function keys F3 to F6 and have four TTY sessions open if you choose. For example, you could be logged into tty3 and press Ctrl+Alt+F6 to go to tty6.
您可以将功能键 Ctrl+Alt 与功能键 F3 到 F6 一起使用,并根据需要打开四个 TTY 会话。例如,您可以登录到 tty3 并按 Ctrl+Alt+F6 转到 tty6。

tty6 console

To get back to your graphical desktop environment, press Ctrl+Alt+F2.
若要返回到图形桌面环境,请按 Ctrl+Alt+F2。

Pressing Ctrl+Alt+F1 will return you to the login prompt of your graphical desktop session.
按 Ctrl+Alt+F1 将返回图形桌面会话的登录提示。

At one time, Ctrl+Alt+F1 through to Ctrl+Alt+F6 would open up the full-screen TTY consoles, and Ctrl+Alt+F7 would return you to your graphical desktop environment. If you are running an older Linux distribution, this might be how your system behaves.
有一次,Ctrl+Alt+F1 到 Ctrl+Alt+F6 将打开全屏 TTY 控制台,而 Ctrl+Alt+F7 将返回到图形桌面环境。如果您运行的是较旧的 Linux 发行版,则这可能是您的系统的行为方式。

This was tested on current releases of Manjaro, Ubuntu, and Fedora and they all behaved like this:
这在 Manjaro、Ubuntu 和 Fedora 的当前版本上进行了测试,它们的行为都是这样的:

  1. Ctrl+Alt+F1: Returns you to the graphical desktop environment log in screen.
    Ctrl+Alt+F1:返回到图形桌面环境登录屏幕。
  2. Ctrl+Alt+F2: Returns you to the graphical desktop environment.
    Ctrl+Alt+F2:返回到图形桌面环境。
  3. Ctrl+Alt+F3: Opens TTY 3.
    Ctrl+Alt+F3:打开 TTY 3。
  4. Ctrl+Alt+F4: Opens TTY 4.
    Ctrl+Alt+F4:打开 TTY 4。
  5. Ctrl+Alt+F5: Opens TTY 5.
    Ctrl+Alt+F5:打开 TTY 5。
  6. Ctrl+Alt+F6: Opens TTY 6.
    Ctrl+Alt+F6:打开 TTY 6。

Having access to these full-screen consoles allows people using command-line only installations of Linux—and many Linux servers are configured this way— to have multiple consoles available.
通过访问这些全屏控制台,人们可以使用仅命令行安装的 Linux— 许多 Linux 服务器都是这样配置的 — 以拥有多个可用的控制台。

Ever been working on a Linux machine with a graphical desktop environment and had something cause your session to freeze? Now you can hop over to one of the TTY console sessions so that you can try to rectify the situation.
曾经在具有图形桌面环境的 Linux 机器上工作并且有什么东西导致您的会话冻结吗?现在,您可以跳转到其中一个 TTY 控制台会话,以便您可以尝试纠正这种情况。

You can use top and ps to try to identify the failed application, then use kill to terminate it, or just use shutdown to try to close down as gracefully as the state of the computer will allow.
您可以使用 topps 尝试识别失败的应用程序,然后使用 kill 终止它,或者只使用 shutdown 尝试在计算机状态允许的范围内尽可能优雅地关闭。

Three Little Letters With a Lot of History 三个充满历史气息的小字母

The tty command gets its name from a device from the late 1800s, appeared in Unix in 1971, and is part of Linux and Unix-like operating systems to this day.
tty 命令得名于 1800 年代后期的设备,于 1971 年出现在 Unix 中,至今仍是 Linux 和类 Unix 操作系统的一部分。

The little chap has quite a tale behind him.
这个小家伙背后有一个故事。


via:

  • What is a TTY on Linux? (and How to Use the tty Command By Dave McKay Published Jul 15, 2019

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/802650.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

每日一题,力扣leetcode Hot100之49. 字母异位词分组

该题用哈希表解答,具有统一特征的作为哈希表的键名,然后满足要求的作为值 解法一: 我们将每个字符串进行排序,如果排序后的结果相同,则可以认为是字母异位词,我们将排序后的结果作为哈希表的key&#xff…

智能听诊器:宠物健康监测的革新者

宠物健康护理领域迎来了一项激动人心的技术革新——智能听诊器。这款创新设备以其卓越的精确度和用户友好的操作,为宠物主人提供了一种全新的健康监测方法。 使用智能听诊器时,只需将其放置在宠物身上,它便能立即捕捉到宠物胸腔的微小振动。…

S274多功能可编程RTU在智慧水务远程水质检测系统中的应用案例

钡铼第四代RTU S274作为一款多功能可编程的无线工业物联网数据监测采集控制短信报警终端,为智慧水务领域提供了强大的技术支持和解决方案。 技术概述与特点 钡铼S274基于UCOSII嵌入式实时操作系统,支持多种通信协议包括短信和MQTT,能够接入…

2024嘶吼网络安全产业图谱(高清完整版)

在数字化和智能化浪潮的推动下,网络安全产业正处于一个快速变革的时期。从传统的防御手段和被动的威胁应对,到如今主动预防和智能检测技术的普及,网络安全领域的焦点和需求正不断演进。为了更好的理解当前网络安全产业现状和未来发展方向&…

jeecgboot项目不知道什么原因启动出来8080端口后就不下去了,要等上10多分钟才出来接口地址等正常情况

因为这个项目license问题无法开源,更多技术支持与服务请加入我的知识星球。 1、项目中途不知道什么原因,就出现下面情况 具体如下: 2024-07-15 15:08:15.767 [main] [34mINFO [0;39m [36mliquibase.changelog:30[0;39m - Reading from jeec…

【LeetCode】十七、并查集

文章目录 1、并查集Union Find2、并查集find的优化:路径压缩 Quick find3、并查集union的优化:权重标记 1、并查集Union Find 并查集,一种树形的数据结构,处理不相交的两个集合的合并与查询问题。 【参考:&#x1f4…

优化 Java 数据结构选择与使用,提升程序性能与可维护性

优化 Java 数据结构选择与使用,提升程序性能与可维护性 引言 在软件开发中,数据结构的选择是影响程序性能、内存使用以及代码可维护性的关键因素之一。Java 作为一门广泛使用的编程语言,提供了丰富的内置数据结构,如数组、链表、…

python用selenium网页模拟时xpath无法定位元素解决方法2

有时我们在使用python selenium xpath时,无法定位元素,红字显示no such element。上一篇文章写了1种情况,是包含iframe的,详见https://blog.csdn.net/Sixth5/article/details/140342929。 本篇写第2种情况,就是xpath定…

嵌入式人工智能(9-基于树莓派4B的PWM-LED呼吸灯)

1、PWM简介 (1)、什么是PWM 脉冲宽度调制(PWM),是英文“Pulse Width Modulation”的缩写,简称脉宽调制,是在具有惯性的系统中利用微处理器的数字输出来对模拟电路进行控制的一种非常有效的技术,广泛应用在从测量、通信到功率控制…

Open3D 最小二乘法拟合点云平面

目录 一、概述 1.1最小二乘法原理 1.2实现步骤 1.3应用场景 二、代码实现 2.1关键函数 2.2完整代码 三、实现效果 3.1原始点云 3.2matplotlib可视化 3.3平面拟合方程 前期试读,后续会将博客加入该专栏,欢迎订阅 Open3D点云算法与点云深度学习…

【内网穿透】打洞笔记

文章目录 前言原理阐述公网sshfrp转发服务 实现前提第一步:第二步第三步第四步 补充第五步(希望隧道一直开着)sftp传数据(嫌云服务器上的网太慢) 前言 租了一个云服务器,想用vscode的ssh远程连接&#xff…

Java面试八股之简述redis常见的性能问题和解决方案

简述redis常见的性能问题和解决方案 Redis作为一款高性能的键值存储系统,虽然设计用于提供低延迟的读写操作,但在特定场景下仍可能出现性能瓶颈。下面列出了一些常见的Redis性能问题及其解决方案: 常见性能问题 内存使用过高 Redis是内存…

支付宝低代码搭建电商小程序,无需编程,可视化操作

大家好,我是小悟 在数字化浪潮的推动下,为了更快速、高效地搭建电商小程序,支付宝低代码平台凭借其独特优势,为商家提供了便捷的解决方案。 支付宝低代码平台犹如一座精心打造的智慧工坊,让电商小程序的搭建变得轻而易…

生成树(STP)协议

一、生成树的技术背景 1、交换机单线路上链,存在单点故障,上行线路及设备都不具备冗余性,一旦链路或上行设备发生故障,网络将面临断网。 总结:以下网络不够健壮,不具备冗余性。 2、因此引入如下网络拓扑结构: 上述冗余拓扑能够解决单点故障问题,但同时冗拓扑也带来了…

多级表头固定列问题

父级的width,是需要固定的列的width的总和 参考: el-table 多级表头下对应列的固定

国产麒麟、uos在线编辑word文件并控制编辑区域(局部编辑)

windows系统也适用,该插件可同时支持windows和国产系统 在实际项目开发中,以下场景可能会用到Word局部编辑功能: 合同审批公文流转策划设计报告汇签单招投标(标书文件)其他,有模板且需要不同人员协作编辑…

OpenGL笔记十三之Uniform向量数据传输、使用glUniform3f和glUniform3fv

OpenGL笔记十三之Uniform向量数据传输、使用glUniform3f和glUniform3fv —— 2024-07-14 晚上 bilibili赵新政老师的教程看后笔记 code review! 文章目录 OpenGL笔记十三之Uniform向量数据传输、使用glUniform3f和glUniform3fv1.glUniform3f1.1.运行1.2.vs1.3.fs1.4.shader.…

<数据集>竹子缺陷检测数据集<目标检测>

数据集格式:VOCYOLO格式 图片数量:2953张 标注数量(xml文件个数):2953 标注数量(txt文件个数):2953 标注类别数:3 标注类别名称:[Bud, Sprouted_Bud, Damage_Bud] 序号类别名称图片数框数1Bud2288229…

LintcCode 468 · 对称二叉树【简单 二叉树 递归 Java】

题目 题目链接: https://www.lintcode.com/problem/468/description?showListFetrue&page1&problemTypeId2&tagIds371&orderingid&pageSize50 思路 递归 Java代码 /*** Definition of TreeNode:* public class TreeNode {* public int…