Linux 上 TTY 的起源

news2024/11/15 17:39:41

注:机翻,未校对。


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.coloradmin.cn/o/1928689.html

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

相关文章

【边缘计算网关教程】6.松下 Mewtocol TCP 协议

前景回顾:【边缘计算网关教程】5.三菱FX3U编程口通讯-CSDN博客 松下 Mewtocol TCP 协议 适配PLC:松下FP0H 松下XHC60ET 1. 硬件连接 Mewtocol TCP协议采用网口通信的方式,因此,只需要保证网关的LAN口和松下PLC的IP在一个网段即…

STM32怎么把VDD与VSS引脚配置为GPIO?

在 STM32 微控制器中,VDD 和 VSS 引脚是供电引脚,分别用于电源和接地。我收集归类了一份嵌入式学习包,对于新手而言简直不要太棒,里面包括了新手各个时期的学习方向编程教学、问题视频讲解、毕设800套和语言类教学,敲个…

使用base64通用文件上传

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

变量筛选—特征包含信息量

在变量筛选中,通过衡量特征所包含信息量大小,决定是否删除特征,常用的指标有单一值占比、缺失值占比和方差值大小。单一值或缺失值占比越高,表示特征包含信息量越少,不同公司设置不同阈值,一般单一值、缺失值占比高于95%,建议删除。方差值越小,代表特征包含信息量越小。…

JMeter进行HTTP接口测试的技术要点

参数化 用户定义的变量 用的时候 ${名字} 用户参数 在参数列表中传递 并且也是${} csv数据文件设置 false 不忽略首行 要首行 从第一行读取 true 忽略首行 从第二行开始 请求时的参数设置&#xff1a; 这里的名称是看其接口需要的请求参数的名称 这里的变量名称就是为csv里面…

C语言程序设计实例2

C语言程序设计2 问题2_1代码2_1结果2_1 问题2_2代码2_2结果2_2 问题2_3代码2_3结果2_3 问题2_1 函数 f u n fun fun的功能是&#xff1a;计算如下公式前 n n n项的和&#xff0c;并作为函数值返回。 S 1 3 2 2 3 5 4 2 5 7 6 2 ⋅ ⋅ ⋅ ( 2 n − 1 ) ( 2 n 1 ) …

Linux操作系统——数据库

数据库 sun solaris gnu 1、分类&#xff1a; 大型 中型 小型 ORACLE MYSQL/MSSQL SQLITE DBII powdb 关系型数据库 2、名词&#xff1a; DB 数据库 select update database DBMS 数据…

Sql语句之增删改查(CRUD)

Sql语句的书写也被称之为CRUD&#xff0c;即C&#xff08;Create增加&#xff09;R&#xff08;Retrieve添加&#xff09;U&#xff08;Update更新&#xff09;D&#xff08;Delete删除&#xff09;四个操作的首字母。 我们先来看增、删、改这三个相对较为简单&#xff0c;语法…

string+迭代器

int main(){ string s0; string s1("hello word"); cout<<s1<<endl; //遍历string,下标[] for(size_t i0;i<s1.size();i) { cout<<s1[i]<<""; } cout<<endl; } 注意&#xff1a;这里size_t不算/0 迭代器 int main() {st…

Open3D 生成多个球形点云

一、概述 使用 Open3D 创建一个三角网格的球体&#xff0c;并从中均匀采样点生成点云&#xff0c;同时可以指定球体的半径和中心位置。生成 5 个不同大小和位置的圆球形点云&#xff0c;并将它们合并成一个点云以进行显示。 二、代码实现 import open3d as o3d import numpy …

Django任务管理

1、用django-admin命令创建一个Django项目 django-admin startproject task_manager 2、进入到项目下用命令创建一个应用 cd task_manager python manage.py startapp tasks 3、进入models.py定义数学模型 第2步得到的只是应用的必要空文件&#xff0c;要开始增加各文件实际…

博客都在使用的主题切换使用vue2实现思路

效果展示 步骤 1-变量定义css主题色 2-html初始化主题样式 3-vuex存储主题变量&#xff0c;点击触发修改根元素html的样式 4-method触发方法 mutation使用commit action使用dispatch 5-App组件引入该css文件&#xff0c;使用即可 6-将其加入本地存储&#xff0c;刷新后保持主…

【Git分支管理】分支合并冲突及其解决

目录 0.合并冲突 1.创建和切换dev1 ​2.dev1 bbb on dev branch ​3.master ccc on dev branch 4.dev1和master合并冲突 5.合并冲突解决 ​6.git log查看合并流程图 先提交再合并 0.合并冲突 在使用git进行合并操作的时候&#xff0c;在合并两个分支的时候就有可能出…

鹧鸪云户用业务管理系统:全流程管理+源码部署

在当今数字化转型的浪潮中&#xff0c;企业对于高效、灵活且定制化的业务管理系统需求日益增长。为满足这一市场需求&#xff0c;鹧鸪云户用业务管理系统应运而生&#xff0c;它以“全流程管理源码部署”为核心优势&#xff0c;为企业提供了一套集成化、可扩展且易于维护的解决…

最新版康泰克完整版- Kontakt v7.10.5 for Win和Mac,支持m芯片和intel,有入库工具

一。世界最受欢迎的采样器的新篇章 Native Instruments Kontakt是采样器领域的标准&#xff0c;您将获得高质量的滤波器&#xff0c;在这里您将找到经典的模拟电路和最现代的滤波器。每一个都可以根据您的口味进行定制&#xff0c;并且由于它&#xff0c;您可以获得前所未有的声…

1.6.丢弃法

丢弃法 动机&#xff1a;一个好的模型需要对输入数据的扰动足够健壮&#xff0c;丢弃法就是在层之间加入噪音。也可以在数据中使用噪音&#xff0c;等价与Tikhonov正则 无偏差的加入噪音 ​ 对于数据 x x x&#xff0c;加入噪音后的 x ′ x x′的期望值是不变的&#xff0c;…

一文说透Springboot单元测试

你好&#xff0c;我是柳岸花开。 一、单元测试说明 1 单元测试的优点与基本原则 一个好的单元测试应该具备以下FIRST 原则和AIR原则中的任何一条&#xff1a; 单元测试的FIRST 规则 Fast 快速原则&#xff0c;测试的速度要比较快&#xff0c; Independent 独立原则&#xff0c;…

华为“铁三角模式”在数据类项目中的应用和价值

引言&#xff1a;随着信息技术的飞速发展&#xff0c;企业纷纷踏上数字化转型的道路&#xff0c;希望通过数据分析和智能决策来提升企业竞争力。在这一过程中&#xff0c;数据类项目成为关键&#xff0c;它们旨在构建高效的数据治理和分析平台&#xff0c;为企业决策提供有力支…

数据结构与算法基础-学习-37-平衡二叉树(Avl树)之删除节点

目录 一、知识点回顾 1、二叉搜索树&#xff08;BST&#xff09; 2、平衡二叉树&#xff08;Avl树&#xff09;之查找 二、环境信息 三、实现思路 1、示例图 2、查询 3、删除 &#xff08;1&#xff09;叶子节点&#xff08;无子树节点&#xff09; &#xff08;2&am…

el-table的selection多选表格改为单选

需求场景: 选择表格数据时&#xff0c;需要控制单条数据的操作按钮是否禁用。 效果图: html代码: <div><el-tableref"multipleTable":data"tableData"tooltip-effect"dark"style"width: 100%"selection-change"handl…