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

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

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

浅谈Visual Studio 2022

Visual Studio 2022(VS2022)提供了众多强大的功能和改进,旨在提高开发者的效率和体验。以下是一些关键功能的概述:12 64位支持:VS2022的64位版本不再受内存限制困扰,主devenv.exe进程不再局限于4GB&#xf…

SQL常用数据过滤---IN操作符

在SQL中,IN操作符常用于过滤数据,允许在WHERE子句中指定多个可能的值。如果列中的值匹配IN操作符后面括号中的任何一个值,那么该行就会被选中。 以下是使用IN操作符的基本语法: SELECT column1, column2, ... FROM table_name WH…

用Vue3和WebCola实现3D图的在线展示

本文由ScriptEcho平台提供技术支持 项目地址:传送门 基于Cola.js的网络图绘制 应用场景 Cola.js是一个JavaScript库,用于绘制交互式网络图。它广泛应用于社交网络、知识图谱、生物网络等领域,帮助用户可视化和探索复杂的数据关系。 基本…

c语言唯一一个三目运算符

条件表达式由两个符号(?和:)组成,必须一起使用。要求有三个操作对象,称为三目运算符。 一般形式为 表达式1?表达式2:表达式3 理解如下: a>b?(maxa):(maxb); //相当…

用AI生成Springboot单元测试代码太香了

你好,我是柳岸花开。 在当今软件开发过程中,单元测试已经成为保证代码质量的重要环节。然而,编写单元测试代码却常常让开发者头疼。幸运的是,随着AI技术的发展,我们可以利用AI工具来自动生成单元测试代码,极…

JS+CSS特效:HTML+JS+CSS 实现精致的带二级菜单的头部菜单

本篇,我们来演示一个二级菜单是怎么做出来的。 案例效果图 因为本次内容主要目标是实现顶部的导航菜单,所以我们不关心其他内容。 第一步:清除浏览器默认样式 & 添加基本样式 *{ margin: 0px; padding: 0px; box-sizing: border-box; …

万界星空科技电线电缆行业MES系统核心功能

在日新月异的科技浪潮中,电线电缆行业作为国民经济的重要支柱,正面临着前所未有的挑战与机遇。如何在激烈的市场竞争中脱颖而出,实现生产效率与产品质量的双重飞跃,成为了每一家线缆企业亟需解决的课题。万界星空科技,…

电池放电倍率

电池放电倍率是指电池在单位时间内放电的速率与其额定容量之比 ,放电倍率越大,表示电池能够在较短的时间内释放更多的电能。一般来说,电池的放电倍率会影响其使用时的性能和寿命。 电池的放电倍率主要取决于其设计和制造工艺。一般来说&#…

Github 2024-07-17 开源项目日报 Top10

根据Github Trendings的统计,今日(2024-07-17统计)共有10个项目上榜。根据开发语言中项目的数量,汇总情况如下: 开发语言项目数量非开发语言项目3Python项目3Rust项目2TypeScript项目2MDX项目1项目化学习 创建周期:2538 天协议类型:MIT LicenseStar数量:161973 个Fork数量…

气象数据文件名解析:使用正则表达式提取时间信息

气象数据文件名解析:使用正则表达式提取时间信息 前言 在处理大量气象数据文件时,文件名往往携带了关键的元数据信息,如日期、时间、地点、测量设备等。其中,时间信息尤为重要,因为它帮助我们理解数据的时效性和用于…

2024 50+行业大模型应用解决方案全解

第一章:以“生成”能力赋能产业智慧化 从当前大模型的行业应用发展中可以看到,现阶段的大模型更适合于企业的“生成”任务,而非“决策”任务。 “生成”任务主要指文本生成、对话系统、语言翻译等,大模型可以通过分析大量文本数…

算法项目报告:物流中的最短路径问题

问题描述 物流问题 有一个物流公司需要从起点A到终点B进行货物运输,在运输过程中,该公司需要途径多个不同的城市,并且在每个城市中都有一个配送站点。为了最大程度地降低运输成本和时间,该公司需要确定经过哪些配送站点&#xff…

<数据集>猫狗识别数据集<目标检测>

数据集格式:VOCYOLO格式 图片数量:3686张 标注数量(xml文件个数):3686 标注数量(txt文件个数):3686 标注类别数:2 标注类别名称:[cat, dog] 序号类别名称图片数框数1cat118811892dog24982498 使用标…

印尼语翻译通:AI驱动的智能翻译与语言学习助手

在这个多元文化交织的世界中,语言是连接我们的桥梁。印尼语翻译通,一款专为打破语言障碍而生的智能翻译软件,让您与印尼语的世界轻松接轨。无论是商务出差、学术研究,还是探索印尼丰富的文化遗产,印尼语翻译通都是您的…

win10安装Docker Desktop启动失败闪退解决方案和Docker Desktop历史版本下载

我的系统是Windows 10 专业版,最近想安装docker desktop,安装最新版本后启动不了,一直报WSL update failed,过一会还闪退,百度各种方法还是没办法解决。 解决方法: 最后安装旧版本才正常启动(…

怎么注册一个小程序

目录 开始申请账号选择注册的账号类型填写邮箱和密码激活邮箱填写主体信息选择主体类型 安装开发工具你的第一个小程序编译预览相关链接 开始 开发小程序的第一步,你需要拥有一个小程序账号,通过这个账号你就可以管理你的小程序。 跟随这个教程&#x…

MySQL 数据库 - SQL

SQL通用语法 SQL通用语法 SQL语句可以单行或者多行书写,以分号结尾。SQL语句可以使用空格/缩进来增强语句的可读性。 注意:空格和缩进的个数是没有限制的,可以是 “一个” 也可以是 “多个”。MySQL数据库的SQL语句不区分大小写,…

【转型Web3开发第二课】Dapp开发入门基础 | 02 | MetaMask配置网络

本文首发于公众号:Keegan小钢 前言 完成了《转型 Web3 开发第一课》之后,得到了不少读者的认可,很多都在问什么时候开始下一课,近期终于抽出了时间开始搞起这第二课。 这第二课的主题为「Dapp开发入门基础」,即想要转…

【Linux】Ubuntu部署K8S集群-图文并茂(超详细)

Ubuntu部署K8S集群 1. 模版机系统环境准备1.1 安装Ubuntu1.2 设置静态IP地址 2. 主机准备2.1 使用模板机创建主机2.2 主机配置2.2.1 修改静态IP2.2.2 修改主机名2.2.3 主机名-IP地址解析2.2.4 时间同步2.2.5 内核转发、网桥过滤配置2.2.6 安装ipset和ipvsadm2.2.7 关闭SWAP分区…

Android调用FFmpeg解码MP3文件并使用AudioTrack播放操作详解

文章目录 总体流程Android读取MP3文件调用FFmpeg进行MP3文件解码AudioTrack播放PCM原理工作原理1. 缓冲区和流模式2. 缓冲区管理3. 音频渲染流程4. 缓冲区大小和延迟5. 线程和同步 使用示例 使用JNI调用AudioTrack播放PCM1.通过JNI创建AudioTrack对象2.调用AudioTrack的write方…