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`?