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://www.mzph.cn/bicheng/47362.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

debian 实现离线批量安装软件包

前言 实现在线缓冲需要的软件和对应依赖的包,离线进行安装 ,用于软件封装。 测试下载一个gcc和依赖环境,关闭默认在线源,测试离线安装gcc和依赖环境 兼容 debian ubuntu/test 测试下载安装包到目录 vim /repo_download.sh #!…

【数据结构】算法复杂度

算法复杂度 数据结构算法复杂度 大o渐进表示法空间复杂度 数据结构 数据结构:是计算机存储和组织数据的方式。 比如打开一个网页,我们看到的文字就是数据,这些数据需要用一个结构来把他管理起来,我们称之为:数据结构 …

基于springboot3实现单点登录(一): 单点登录及其相关概念介绍

引言 应网友要求,从本文开始我们将实现一套基于springboot3springsecurity的单点登录认证系统。 单点登录的实现方式有多种,接下来我们会以oauth2为例来介绍和实现。 单点登录介绍 单点登录(Single Sign-On,简称SSO&#xff0…

nftables(7)集合(SETS)

简介 在nftables中,集合(sets)是一个非常有用的特性,它允许你以集合的形式管理IP地址、端口号等网络元素,从而简化规则的配置和管理。 nftables提供了两种类型的集合:匿名集合和命名集合。 匿名集合&…

使用base64通用文件上传

编写一个上传文件的组件 tuku,点击图片上传后使用FileReader异步读取文件的内容&#xff0c;读取完成后获得文件名和base64码&#xff0c;调用后端uploadApi,传入姓名和base64文件信息&#xff0c;后端存入nginx中&#xff0c;用于访问 tuku.ts组件代码&#xff1a; <templa…

系统测试-白盒测试学习

目录 1、语句覆盖法&#xff1a; 2、判定覆盖法&#xff1a; 3、条件覆盖法&#xff1a; 4、判定条件覆盖&#xff1a; 5、条件组合的覆盖&#xff1a; 6、路径覆盖&#xff1a; 黑盒&#xff1a;需求 白盒&#xff1a;主要用于单元测试 1、语句覆盖法&#xff1a; 程序…

OSU!题解(概率dp)

题目&#xff1a;OSU! - 洛谷 思路&#xff1a; 设E()表示截止到i所获得的分数&#xff1b; 对于到i点的每一个l&#xff0c;如果第i1点为1&#xff0c;那么会新增分数3*l^23*l1; 就有递推公式方程&#xff1a; E()E()p[i1]p*(3*l^23*l1);(p代表截止到i获得长度l的概率)&a…

怎样在 PostgreSQL 中优化对多表关联的连接条件选择?

&#x1f345;关注博主&#x1f397;️ 带你畅游技术世界&#xff0c;不错过每一次成长机会&#xff01;&#x1f4da;领书&#xff1a;PostgreSQL 入门到精通.pdf 文章目录 怎样在 PostgreSQL 中优化对多表关联的连接条件选择一、理解多表关联的基本概念二、选择合适的连接条件…

【C++】拷贝构造函数及析构函数

&#x1f4e2;博客主页&#xff1a;https://blog.csdn.net/2301_779549673 &#x1f4e2;欢迎点赞 &#x1f44d; 收藏 ⭐留言 &#x1f4dd; 如有错误敬请指正&#xff01; &#x1f4e2;本文由 JohnKi 原创&#xff0c;首发于 CSDN&#x1f649; &#x1f4e2;未来很长&#…

dbeaver连接mysql8异常

部署了mysql8&#xff0c;尝试用dbeaver 24.1.2连接它。结果配置完成后测试连接时报错&#xff1a;Public Key Retrieval is not allowed. 按照提示修改驱动属性&#xff1a; allowPublicKeyRetrievaltrue

【BUG】已解决:ValueError: Expected 2D array, got 1D array instead

已解决&#xff1a;ValueError: Expected 2D array, got 1D array instead 欢迎来到英杰社区https://bbs.csdn.net/topics/617804998 欢迎来到我的主页&#xff0c;我是博主英杰&#xff0c;211科班出身&#xff0c;就职于医疗科技公司&#xff0c;热衷分享知识&#xff0c;武汉…

Python | Leetcode Python题解之第238题除自身以外数组的乘积

题目&#xff1a; 题解&#xff1a; class Solution:def productExceptSelf(self, nums: List[int]) -> List[int]:length len(nums)# L 和 R 分别表示左右两侧的乘积列表L, R, answer [0]*length, [0]*length, [0]*length# L[i] 为索引 i 左侧所有元素的乘积# 对于索引为…

人工智能 (AI) 应用:一个异常肺呼吸声辅助诊断系统

关键词&#xff1a;深度学习、肺癌、多标签、轻量级模型设计、异常肺音、音频分类 近年来&#xff0c;流感对人类的危害不断增加&#xff0c;COVID-19疾病的迅速传播加剧了这一问题&#xff0c;导致大多数患者因呼吸系统异常而死亡。在这次流行病爆发之前&#xff0c;呼吸系统…

SCI一区级 | Matlab实现GJO-CNN-LSTM-Multihead-Attention多变量时间序列预测

SCI一区级 | Matlab实现GJO-CNN-LSTM-Mutilhead-Attention多变量时间序列预测 目录 SCI一区级 | Matlab实现GJO-CNN-LSTM-Mutilhead-Attention多变量时间序列预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 1.Matlab实现GJO-CNN-LSTM-Mutilhead-Attention金豺优化算…

MongoDB自学笔记(三)

一、前文回顾 上一篇文章中我们学习了更新操作&#xff0c;以及讲解了部分的更新操作符&#xff0c;今天我们继续学习剩余的更新操作符。 二、更新操作符 1、$rename 语法&#xff1a;{ $rename: { < field1 >: < newName1 >, < field2 >: < newName2…

力扣刷题之978.最长湍流子数组

题干要求&#xff1a; 给定一个整数数组 arr &#xff0c;返回 arr 的 最大湍流子数组的长度 。 如果比较符号在子数组中的每个相邻元素对之间翻转&#xff0c;则该子数组是 湍流子数组 。 更正式地来说&#xff0c;当 arr 的子数组 A[i], A[i1], ..., A[j] 满足仅满足下列条…

FPGA笔试

半加器和全加器的区别&#xff1a; 1、半加器不考虑输入的进位&#xff0c;称之为半加。 2、全加器反之&#xff0c;考虑进位。 SRAM/DRAM优缺点对比_sram和dram的主要区别及优缺点-CSDN博客 消除竞争冒险的方法 ①滤波电容&#xff1a;因为尖峰脉冲很窄&#xff0c;用很小的…

棱镜七彩上榜《嘶吼2024网络安全产业图谱》两大领域

7月16日&#xff0c;嘶吼安全产业研究院正式发布《嘶吼2024网络安全产业图谱》&#xff0c;棱镜七彩凭借在软件供应链安全领域出色的技术能力和优异的市场表现&#xff0c;上榜软件成分分析&#xff08;SCA&#xff09;、源代码安全两项细分领域。 据悉&#xff0c;本次《嘶吼2…

成为CMake砖家(2): macOS创建CMake本地文档的app

大家好&#xff0c;我是白鱼。 使用 CMake 的小伙伴&#xff0c; 有的是在 Windows 上&#xff0c; 还有的是在 macOS 上。之前咱们讲了 windows 上查看 cmake 本地 html 文档的方式&#xff0c; 这篇讲讲 macOS 上查看 cmake 本地 html 文档的方法。 1. 问题描述 当使用 CMa…

防火墙--带宽管理

目录 核心思想 带宽限制 带宽保证 连接数的限制 如何实现 接口带宽 队列调度 配置位置 在接口处配置 带宽策略配置位置 带宽通道 配置地方 接口带宽、带宽策略和带宽通道联系 配置顺序 带块通道在那里配置 选项解释 引用方式 策略独占 策略共享 重标记DSCP优先…