Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
Are there practical differences between the way the pseudo-terminal and the terminal are implemented to accommodate the connection differences? –  rubixibuc Dec 28 '11 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. –  Gilles Dec 28 '11 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 Dec 28 '11 at 22:21
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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