2

I'm trying to understand this topic but, apparently, for my brain it is too hard.

Terminal device entries normally reside in two directories: /dev and /dev/pts. The /dev directory contains entries for virtual consoles (e.g., /dev/tty1) and BSD pseudoterminals. The /dev/pts directory contains entries for (System V style) pseudoterminal slave devices

This is extracted from the "Linux program interface" book.

According to the assertion above, in the /dev/pts directory i can find the slave part of a Pseudo Terminal.

Then why if i use the tty command it prints /dev/pts/0? Is the assertion above incomplete? I mean, is there a relationship between terminal and Pseudo Terminal? Because if in /dev/pts i can only find salve parts of pseudo terminal pair, is the terminal implemented like a Pseudo Terminal?

Always from the "Linux program iterface" book:

In a normal login session, the shell is connected directly to the user’s terminal.

So i can make a scheme according to this assertion:

enter image description here

But if my terminal is associated with a slave device (like tty command says), the scheme is not true at all and it becommes:

enter image description here

After this considerations, is the terminal implemented like a Pseudo Terminal pair (with slave and master) or it is just implemented like a slave file (or something like that)?

1 Answer 1

1

is there a relationship between terminal and Pseudo Terminal?

Terminals originally were something like these or like these. The terminal device file (/dev/tty1) on a unix system would be connected through the OS to this kind of hardware, often through a serial interface.

If you write to the file, the output appears on the printer (ASR33) or screen (VT100), if you type on the keyboard, it can be read from the file. In addition, it supports special commands (ioctl's) to set things like serial line speed, communication protocols, etc.

A pseudo terminal is a drop-in replacement for a terminal, where the other end is not some kind of hardware, but a second "file" (the master). The slave end acts exactly like the device file for a hardware terminal, so you can connect a shell to it. The master part can be used by an application on the other end to simulate a hardware terminal. For example, xterm uses a pseudo terminal pair, and uses the master part to interface with the X system.

There's a small gotcha: The master part is never visible in the file system. If you want, it's an "invisible file".

Then why if i use the tty command it prints /dev/pts/0?

Because the shell were you are typing this is probably running inside an xterm or similar terminal emulator. Few people today use real hardware terminals.

And yes, your second diagram comes close, if you replace "terminal" with "terminal emulator" (application that emulates a terminal).

And today many people just say "terminal" when they mean "terminal emulator".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.