159

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?

1

3 Answers 3

168

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.

5
  • 1
    What do you mean by the backend is hardware?
    – Motivated
    Commented Jan 14, 2019 at 17:07
  • 2
    @Motivated: en.wikipedia.org/wiki/Computer_terminal Commented Jan 14, 2019 at 17:10
  • 1
    Thanks. I take it that's a historical reference as opposed to contemporary use i.e. it used to be backed by hardware.
    – Motivated
    Commented Jan 14, 2019 at 17:54
  • 3
    So basically a tty is something where there's no user process "on the other end"? Commented Nov 11, 2019 at 16:21
  • 1
    Oldish thread but here's my 2 cents. When hardware was much more expensive, companies would have a central, multi-user system (Unix, Mainframe, etc) with a bunch of connected "dumb" terminals. These just had a screen and keyboard and very simple logic that only knew how to send keystrokes down the wire to the server and to receive screen updates. All actual processing was done on the server. This is what is meant by "backed by hardware". Once personal computers came around, "terminal emulators were created to emulate these dumb terminals and allow someone with a PC to interact with the server.
    – grim_i_am
    Commented May 3, 2022 at 8:34
58

A tty is a regular terminal device (the console on your server, for example).
A pts is a psuedo terminal slave (an xterm or an ssh connection).

man pts has a verbose description of pseudo terminals.

1
1

tty and pts are both related to terminals on Unix-based systems, but they differ in their nature ref

tty (teletype):

  • Represents a physical terminal device. This could be the original concept of a teletypewriter or a modern monitor and keyboard connected directly to the system.
  • Provides a way to interact with the operating system by giving text-based commands and receiving output.
  • Examples of tty devices include /dev/tty1, /dev/ttyS0 (serial port).

pts (pseudo terminal slave):

  • Stands for "pseudo terminal slave." It's a software emulation of a terminal device, not directly connected to physical hardware.
  • Often created by programs like SSH or terminal emulators (e.g., xterm, screen) to provide a terminal experience even without a physical terminal.
  • Works by creating a pair of virtual devices: a master and a slave. The program manages the master side, while the slave side acts like a regular tty for the user.
  • Examples of pts devices follow the naming convention /dev/pts/.
3
  • Wellcome here. However, I can't agree with the wording "Often created by programs like SSH or terminal emulators (e.g., xterm, screen)" since while these programs might actually use pts they are definitely not responsible for creating them.
    – MC68020
    Commented May 4 at 9:34
  • @MC68020 Please give an example
    – Morteza M
    Commented May 7 at 13:44
  • @MortezaM, this is missing a section on ptys. Commented Jul 5 at 9:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .