4

I keep reading on multiple sites that pts device files are used for pseudo-terminals which are "not directly connected to the hardware" (ssh, telnet).

Since xterm running on you machine is directly connected the output on your keyboard and the display on your screen, why does this use a pseudo-terminal device file?

I read the other question regarding ttys pts, ... and it didn't seem to cover this..

Also, what is the need for a "pseudo terminal," if it's ultimately a device file with input and output why does it matter what it's coming from?

Thanks in advance

1
  • xterm is not directly connected to your keyboard and your display. If it was, window focus and minimise would not work. Commented Nov 26, 2019 at 20:54

2 Answers 2

4

There are several things about terminals that are managed inside the kernel, such as keyboard signals (mapping e.g. Ctrl+Z to SIGSTOP), managing foreground and background process groups, an extremely crude line edition mechanism, sending SIGHUP when the terminal goes away, and other niceties.

With a hardware terminal, the terminal device sits between the application and the hardware. The kind of terminal device depends on the kind of hardware, for example (on Linux) /dev/tty1 for a PC keyboard and screen, /dev/ttyS0 for a terminal connected over a serial line, /dev/ttyUSB0 for a terminal connected over USB, etc.

+-------------+         +-----------------+         +-------------+
| text mode   |         | kernel          |         | peripheral  |
| application |<------->| e.g. /dev/ttyS0 |<------->| e.g. on a   |
|             |         |                 |         | serial port |
+-------------+         +-----------------+         +-------------+

With a terminal emulator, the principle is the same, with the connection still going through a kernel driver, but what's at the other end is also a process.

+-------------+         +-----------------+         +-------------------+
| text mode   |         | kernel          |         | terminal emulator |
| application |<------->| /dev/pts/*      |<------->| e.g. xterm, sshd, |
|             |         |                 |         |      screen, ...  |
+-------------+         +-----------------+         +-------------------+

Xterm, telnetd¹, sshd and the like are not (directly) connected to any hardware. When you type a key on a keyboard, the information goes through the keyboard (the physical device) to the keyboard driver inside the kernel which then relays it to a process that's listening on the keyboard device. If you're in a graphical session, that process is an X server which then relays the information to the process whose window is focussed. Conversely, when a program running inside xterm produces output, xterm transforms this into an order for the X server to display certain characters in a certain font at a certain position. There is no hardware involved anywhere near the process that's processing the input or producing the output, and possibly none at all (e.g. if the xterm window is not visible on the screen, or at least none locally if the terminal is provided by a telnet or ssh server).

¹ The terminal is on the remote (server) side.

6
  • Are there practical differences between the way the pseudo-terminal and the terminal are implemented to accommodate the connection differences?
    – rubixibuc
    Commented Dec 28, 2011 at 1:42
  • @rubixibuc I don't understand your question. Different types of terminal receive input from different sources and send output in different ways. There's a common part for things like process group management and signals. Commented Dec 28, 2011 at 18:00
  • I just meant were there any large differences in the way the terminal device communicated with the emulator now that the terminal is software based. Other than being a pseudo-terminal with the master and slave side, what features did adding a pseudo-terminal offer.
    – rubixibuc
    Commented Dec 28, 2011 at 22:21
  • @Gilles When I type tty into xterm running in GUI, it says /dev/tty6. To clarify, are you saying that bash connects to xterm through a pty, and xterm interacts with the X server to render stuff, which further handles raw I/O(from Kb/Screen) using yet another terminal device, the /device/tty0? What does the tty6 do here? Commented Jan 3, 2018 at 18:12
  • 1
    @forumulator “bash connects to xterm through a pty, and xterm interacts with the X server to render stuff, which further handles raw I/O” correct so far. The raw I/O goes through something that is not called a terminal device. You can think of it as a console device — it has a completely different interface from a terminal. How it actually works depends on the kernel and has changed over time. The X server gets pipeline to the hardware, which may allow it to get/set pixels' colors (framebuffer) or more complex commands (hardware acceleration via the GPU). Commented Jan 3, 2018 at 20:43
0

Here's a link I found that answers the question. It basically says that they were created to move the terminal emulation into user space. It's towards the top of the page.

http://www.linusakesson.net/programming/tty/index.php

You must log in to answer this question.

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