加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-15 09:08:49 所属栏目:安全 来源:网络整理
导读: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是表示当前进程的“控制终端”的特殊文件。 字符设
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读