Skip to content

tty

wikipedia tty (unix)

In computing, tty is a command in Unix and Unix-like operating systems to print the file name of the terminal connected to standard input.[1]

tty stands for TeleTYpewriter.[2]

Example

Given below is a sample output when the command is run

$ tty
/dev/pts/10

man 4 tty

NAME

tty - controlling terminal

DESCRIPTION

The file /dev/tty is a character file with major number 5 and minor number 0, usually of mode 0666 and owner.group root.tty. It is a synonym for the controlling terminal of a process, if any.

In addition to the ioctl(2) requests supported by the device that tty refers to, the ioctl(2) request TIOCNOTTY is supported.

TIOCNOTTY

Detach the calling process from its controlling terminal.If the process is the session leader, then SIGHUP and SIGCONT signals are sent to the foreground process group and all processes in the current session lose their controlling tty.

This ioctl(2) call works only on file descriptors connected to /dev/tty. It is used by daemon processes when they are invoked by a user at a terminal.

This ioctl(2) call works only on file descriptors connected to /dev/tty. It is used by daemon processes when they are invoked by a user at a terminal. The process attempts to open /dev/tty. If the open succeeds, it detaches itself from the terminal by using TIOCNOTTY, while if the open fails, it is obviously not attached to a terminal and does not need to detach itself.

man 1 tty

NAME

​ tty - print the file name of the terminal connected to standard input

SYNOPSIS

tty [OPTION]...

DESCRIPTION

Print the file name of the terminal connected to standard input.

man 8 agetty

NAME

agetty - alternative Linux getty

SYNOPSIS

agetty [options] port [baud_rate...] [term]

DESCRIPTION

agetty opens a tty port, prompts for a login name and invokes the /bin/login command.It is normally invoked by init(8).

agetty has several non-standard features that are useful for hard-wired and for dial-in lines:

stackexchange Difference between pts and tty

Possible Duplicate: What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'?

I always see pts and tty when I use the who command but I never understand how they are different? Can somebody please explain me this?

COMMENTS :

See also How does a Linux terminal work? and what is stored in /dev/pts files and Can we open those?GillesNov 14 '13 at 20:07

A

A tty is a native terminal device, the backend is either hardware or kernel emulated.

A pty (pseudo terminal device) is a terminal device which is emulated by an other program (example: xterm, screen, or ssh are such programs). A pts is the slave part of a pty.

(More info can be found in man pty.)

Short summary:

A pty is created by a process through posix_openpt() (which usually opens the special device /dev/ptmx), and is constituted by a pair of bidirectional character devices:

  1. The master part, which is the file descriptor obtained by this process through this call, is used to emulate a terminal. After some initialization, the second part can be unlocked with unlockpt(), and the master is used to receive or send characters to this second part (slave).
  2. The slave part, which is anchored in the filesystem as /dev/pts/x (the real name can be obtained by the master through ptsname() ) behaves like a native terminal device (/dev/ttyx). In most cases, a shell is started that uses it as a controlling terminal.