/dev/tty 有什么特别之处? [英] What is special about /dev/tty?

查看:38
本文介绍了/dev/tty 有什么特别之处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

What does c at the beginning mean? When I do something like pwd > /dev/tty it prints to the stdout. What does the file /dev/tty contain?

推荐答案

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

The 'c' means it's a character device. tty is a special file representing the 'controlling terminal' for the current process.

字符设备

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

Unix supports 'device files', which aren't really files at all, but file-like access points to hardware devices. A 'character' device is one which is interfaced byte-by-byte (as opposed to buffered IO).

TTY

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

/dev/tty is a special file, representing the terminal for the current process. So, when you echo 1 > /dev/tty, your message ('1') will appear on your screen. Likewise, when you cat /dev/tty, your subsequent input gets duplicated (until you press Ctrl-C).

/dev/tty 本身不包含"任何内容,但您可以从中读取和写入(对于它的价值).我想不出它有什么好的用途,但是有一些类似的文件对于简单的 IO 操作非常有用(例如,/dev/ttyS0 通常是您的串行端口)

/dev/tty doesn't 'contain' anything as such, but you can read from it and write to it (for what it's worth). I can't think of a good use for it, but there are similar files which are very useful for simple IO operations (e.g. /dev/ttyS0 is normally your serial port)

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

/dev/tty 代表当前的控制终端(如果有的话)过程.找出哪些 tty 附加到哪些进程使用shell 提示符下的ps -a"命令(命令行).看着那(这tty"列.对于您所在的 shell 进程,/dev/tty 是您现在正在使用的终端.在 shell 提示符下键入tty"以查看它是(参见手册页 tty(1))./dev/tty 就像一个链接具有一些附加功能的实际终端设备名称C 程序员:请参阅手册页 tty(4).

/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

这篇关于/dev/tty 有什么特别之处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆