微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

unix – /dev/tty有什么特别的?

ls -la / dev / tty显示输出
crw-rw-rw- 1 root tty 5,0 Dec 14 22:21 /dev/tty

c在开头是什么意思?当我做像pwd> / dev / tty打印到stdout。文件/ dev / tty包含什么?

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

字符设备

Unix支持’设备文件’,这根本不是真正的文件,而是文件式的硬件设备访问点。
“字符”设备是逐字节接口的设备(与缓冲IO相反)。

TTY

/ dev / tty是一个特殊文件,表示当前进程的终端。所以,当你回显1> / dev / tty,您的消息(‘1’)将出现在您的屏幕上。同样,当你的cat / dev / tty,你的后续输入被重复(直到你按Ctrl-C)。

/ dev / tty不包含任何东西,但你可以从它读取并写入它(值得)。我不能想到一个很好的使用它,但有类似的文件,这是非常有用的简单的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

原文地址:https://www.jb51.cc/bash/389239.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐