Skip to content

Commit

Permalink
chore: Update terminal information and add table of contents with per…
Browse files Browse the repository at this point in the history
…malinks to documentation
  • Loading branch information
ricolxwz committed Jun 9, 2024
1 parent c9fb246 commit 34d7dbf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
18 changes: 14 additions & 4 deletions docs/命令行技能/终端.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@ icon: simple/gnometerminal

## 终端

终端是用户和计算机系统交互的接口, 最初指的是物理设备. 在计算机诞生之前, 人们发明了[电传打印机](https://zh.wikipedia.org/wiki/%E9%9B%BB%E5%82%B3%E6%89%93%E5%AD%97%E6%A9%9F "Teletypewriter"), 通过电线点对点链接, 用于远距离传送电报信息. 后来人们将其连接到早期的大型计算机上, 作为输入和输出设备.
终端是用户和计算机系统交互的接口, 最初指的是物理设备. 在计算机诞生之前, 人们发明了[电传打字机](https://zh.wikipedia.org/wiki/%E9%9B%BB%E5%82%B3%E6%89%93%E5%AD%97%E6%A9%9F), 通过电线点对点链接, 用于远距离传送电报信息. 后来人们将其连接到早期的大型计算机上, 作为输入和输出设备. 电传打字机(**T**ele**TY**pewriter)就是曾经计算机的终端, 缩写为TTY.

## 终端类型
为了把不同型号的电传打字机接入计算机, 需要在操作系统内核安装驱动, 屏蔽掉所有底层的细节. 这就是TTY驱动的作用. 此外, 操作系统还有一个UART驱动程序, 管理字节的物理传输, 包括奇偶校验和流量控制.

### [终端模拟器]("Terminal Emulator")
## [终端模拟器]("Terminal Emulator")

### [伪终端]("Pseudo Terminal, PTY")
今天, 虽然电传打字机已经进了博物馆, 但是Linux/Unix还是保留了当初的TTY驱动. 终端不再只是一个需要通过UART连接到计算机上的物理设备, 它变成了一个内核模块, 可以直接向TTY驱动发送字符, 从TTY驱动读取响应然后打印到屏幕上, 也就是说, 这个模块可以模拟物理终端设备, 因此被称为[终端模拟器]("Terminal Emulator").

如何得到一个终端模拟器呢? 如果你有机会访问[控制台]("Console"), 那么你默认情况下能打开6个终端模拟器. Linux上这种模拟的文本终端也被称为[虚拟终端]("Virtual Terminal"). 每个虚拟终端都由一个特殊的设备文件`/dev/tty[n]`表示.

## [伪终端]("Pseudo Terminal, PTY")

[终端模拟器]("Terminal Emulator")是运行在内核的模块, 我们也可以让终端模拟程序运行在用户区, 运行在用户区的终端模拟程序, 被称为[伪终端]("Pseudo Terminal, PTY").

PTY运行在用户区, 更加的安全和灵活, 同时保留了TTY驱动, 常用的伪终端有xterm, gnome-terminal, 以及远程终端ssh. 由于伪终端和TTY驱动交互[^2]不是考察内容, 所以没有详细解释.

## Shell

Shell指的是命令解释器, 它不负责处理键盘事件, 也不负责字符的现实, 这是终端要为它处理好的. Shell是用户空间的应用程序, 通常由终端fork出来, 是终端的子进程, 通常我们用的比较多的是Bash, Zsh和sh.

### Bash Shell

在Linux下, 默认的shell是Bash, 也可以称为Bourne-Again Shell, 由Stephen Bourne开发. 此笔记中所有的命令都和Bash shell适配.
Expand Down
5 changes: 3 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ markdown_extensions:
- footnotes
- def_list
- tables
- toc:
permalink: true
# - toc:
# permalink: true
- pymdownx.arithmatex:
generic: true
- pymdownx.highlight:
Expand All @@ -117,6 +117,7 @@ markdown_extensions:
format: !!python/name:pymdownx.superfences.fence_code_format
plugins:
- search
- open-in-new-tab
nav:
- 开始:
- index.md
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mkdocs-material
mkdocs-material
mkdocs-open-in-new-tab

0 comments on commit 34d7dbf

Please sign in to comment.