From
man tty
tty - print the file name of the terminal connected to standard input
$ tty /dev/pts/2
From APUE:
Historically, the name of the controlling terminal in most versions of the UNIX System has been
/dev/tty
. POSIX.1 provides a runtime function that we can call to determine the name of the controlling terminal.#include <stdio.h> char *ctermid(char *ptr);
$ ls -la /dev/tty crw-rw-rw- 1 root tty 5, 0 May 26 00:16 /dev/tty
So I was wondering if the output of command tty
and the file /dev/tty
both refer to the controlling terminal of the current bash process?
If yes, why does command tty
output a pseudoterminal slave file /dev/pts/2
, which is different from /dev/tty
?
Since the terminal emulator lxterminal
and the bash shell running in it use a pseudoterminal pair, isn't the pseudoterminal slave /dev/pts/2
the controlling terminal of the bash shell?
/dev/tty
and /dev/pts/2
aren't symlinks to one another, so are they different files?
Thanks.
A follow up post what relations are between my current controlling terminal and `/dev/tty`?
/dev/tty
is guaranteed to be a synonym of the controlling terminal. That is,/dev/tty
and the proper name of the controlling terminal will always refer to the same physical or virtual device. – AlexP May 31 '18 at 20:59/dev/tty
is guaranteed to be their controlling terminals. How can a file be different controlling terminals, without being a symlink or hardlink? – Tim May 31 '18 at 21:13/dev/tty
mean for the process? – Tim Dec 01 '18 at 02:04/dev/tty
will fail and seterrno
toENODEV
. – AlexP Dec 01 '18 at 03:21