> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/4.3-bsd-unix-cao-zuo-xi-tong-she-ji-yu-shi-xian/di-san-bu-fen-io-xi-tong/9.3.-yong-hu-jie-mian.md).

# 9.3 用户界面

多数终端线路默认使用的终端行规程源自 UNIX 32V 和第七版 UNIX 中的规程。这一行规程的用户界面，即所谓旧终端驱动（old terminal driver），在 4.3BSD 中仍然存在。从 4.1BSD 起，系统加入了旧驱动的扩展，为作业控制支持新信号，并为 CRT 终端提供逻辑行编辑设施。扩展后的驱动称为新终端驱动（new terminal driver），保留了旧驱动的接口，并在原有选项和模式之外增加了新的。新驱动添加的若干选项修改了既有驱动的基本模式，使接口显得相当杂乱。新旧两种终端行规程由同一个终端驱动实现，驱动按当前规程改变行为。

控制终端行规程的主用户界面是 `ioctl` 系统调用。它用来更改规程、设置和读取特殊处理字符与模式的值、设置和读取硬件串行线参数，以及做其他控制操作。多数 `ioctl` 操作除文件描述符和命令外还要求一个参数：一个整数或结构的地址，系统从它取得参数，或把返回信息放进去。下面这组 `ioctl` 命令专门适用于标准终端行规程，不过所有行规程都必须至少支持头两条；其他规程一般支持另外的 `ioctl` 命令。

TIOCGETD　　以整数常量取得本线路行规程的标识

TIOCSETD　　设置本线路的规程

TIOCGETP　　取得本线路的基本（旧终端驱动）参数，包括线路速度、基本模式和 erase、kill 字符

TIOCSETP　　设置本线路的基本参数

TIOCSETN　　设置本线路的基本参数而不冲掉输入

TIOCGETC　　取得基本特殊字符集（erase 和 kill 之外）的值

TIOCSETC　　设置旧终端驱动支持的特殊字符（erase 和 kill 之外）的值

TIOCLGET TIOCLSET TIOCLBIS TIOCLBIC　　取得（设置、置位、清除）**本地** 选项——仅新终端驱动使用的那些

TIOCGLTC TIOCSLTC　　取得（设置）**本地** 特殊字符——仅新终端驱动使用的那些

TIOCGWINSZ TIOCSWINSZ　　取得（设置）终端线路的终端或窗口大小；窗口大小包括以字符计的宽和高，以及（图形显示上可选）以像素计的宽和高

这组终端 `ioctl` 命令显示了终端接口所支持选项的渐进增长。

TIOCSETP 和 TIOCLSET 设置的参数包括改变终端线路行为的标志。其中 RAW 和 CBREAK 两个标志控制 tty 的总体模式，其余控制附加特性或修改总体模式：RAW 标志把终端设为原始模式；CBREAK 标志设为 cbreak 模式；两者都不设时，终端处于规范模式——正常的逐行模式。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://book.bsdcn.org/4.3-bsd-unix-cao-zuo-xi-tong-she-ji-yu-shi-xian/di-san-bu-fen-io-xi-tong/9.3.-yong-hu-jie-mian.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
