gpt4 book ai didi

unix -/dev/tty 有什么特别之处?

转载 作者:行者123 更新时间:2023-12-03 05:47:48 27 4
gpt4 key购买 nike

ls -la /dev/tty显示输出:

crw-rw-rw- 1 root tty 5, 0 Dec 14 22:21 /dev/tty

c开头是什么意思?当我做类似 pwd > /dev/tty 的事情时它打印到标准输出。/dev/tty 文件包含什么内容?

最佳答案

“c”表示它是一个字符设备。 tty 是一个特殊文件,代表当前进程的“控制终端”。

角色设备

Unix 支持“设备文件”,它们根本不是真正的文件,而是对硬件设备的类似文件的访问点。“字符”设备是一种逐字节连接的设备(与缓冲 IO 相对)。

电传打字机

/dev/tty 是一个特殊文件,代表当前进程的终端。因此,当您 echo 1 >/dev/tty 时,您的消息 ('1') 将出现在屏幕上。同样,当您 cat/dev/tty 时,您的后续输入将被重复(直到您按 Ctrl-C)。

/dev/tty 不“包含”任何此类内容,但您可以从中读取并写入(无论其值(value)如何)。我想不出它有什么好的用途,但是有类似的文件对于简单的 IO 操作非常有用(例如 /dev/ttyS0 通常是你的串行端口)

这句话来自http://tldp.org/HOWTO/Text-Terminal-HOWTO-7.html#ss7.3 :

/dev/tty stands for the controlling terminal (if any) for the current process. To find out which tty's are attached to which processes use the "ps -a" command at the shell prompt (command line). Look at the "tty" column. For the shell process you're in, /dev/tty is the terminal you are now using. Type "tty" at the shell prompt to see what it is (see manual pg. tty(1)). /dev/tty is something like a link to the actually terminal device name with some additional features for C-programmers: see the manual page tty(4).

这是手册页:http://linux.die.net/man/4/tty

关于unix -/dev/tty 有什么特别之处?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8514735/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com