> 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/man/man4/pty.4.md).

# pty.4

`pty` — 旧式兼容伪终端驱动程序

## 名称

`pty`

## 概要

`device pty`

## 描述

`pty` 驱动程序为传统的 BSD 命名方案提供支持，该方案在 [pts(4)](/man/man4/pts.4.md) 取代它之前用于访问伪终端。这种传统命名在 Linux 中仍在使用。当打开设备 **`/dev/ptyXX`** 时，[pts(4)](/man/man4/pts.4.md) 驱动程序会创建新终端。同时会为此终端创建一个名为 **`/dev/ttyXX`** 的设备节点。

`pty` 驱动程序还提供了一个克隆式的 System V **`/dev/ptmx`** 设备。

新代码不应尝试使用此接口分配伪终端。提供它仅为兼容较旧的 C 库（在调用 posix\_openpt(2) 时会尝试打开此类设备）以及运行 Linux 二进制文件。

## 文件

BSD 风格的兼容伪终端驱动程序使用以下设备名：

**`/dev/pty[l-sL-S][0-9a-v]`** 伪终端主设备。

**`/dev/tty[l-sL-S][0-9a-v]`** 伪终端从设备。

**`/dev/ptmx`** 控制设备，打开时返回一个新的主伪终端的文件描述符。

## 诊断

无。

## 参见

posix\_openpt(2), [pts(4)](/man/man4/pts.4.md), [tty(4)](/man/man4/tty.4.md)

## 历史

伪终端驱动程序出现于 4.2BSD。

## 缺陷

与之前的实现不同，PTY 不再使用时即销毁主从设备节点。对不存在的主设备调用 stat(2) 已经会创建新的主设备节点。主设备只能通过打开并关闭来销毁。

`pty` 驱动程序无法卸载，因为它无法确定自己是否正在使用中。


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man4/pty.4.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
