DEV Community

Discussion on: Linux terminals, tty, pty and shell

Collapse
 
1chtulhu profile image
Max Yudkin
  1. XTerm listens for keyboard events and sends the characters to the pty master
  2. The line discipline gets the character and buffers them... It also writes back its input to the master (echoing back).

Hi,

Please, help me to clarify sequence of events:

  1. xterm writes all keystrokes to pty master (fopen-ed /dev/ptmx)
  2. line discipline automatically (managed by tty driver) gets those characters
  3. buffers them and writes(echoes) back to pty master stream (fopen-ed in step 1)
  4. xterm reads from pty master (fopen-ed in step 1) and redraw UI

question 1: why does xterm need echo from line discipline if in step 1 it already writes to pty master?

question 2: what echo operation really does? If it simply writes to pty master, why no recursion occur (pty master <-> line discipline)?

Collapse
 
napicella profile image
Nicola Apicella

Back in the day, terminal were essentially just a peripheral. They were only able to send and receive data to the mainframe. Those terminals were not smart enough (not enough memory or compute) to be able to process the data typed by the user. The mainframe had to do everything for them (including echoing back characters).

A lot changed since then. We have all have plenty of computing power in our laptops and do not need to connect to mainframes anymore. What did not change is the architecture. When laptop started to become common, smart folks decided to reuse the same architecture by replicating in software (in the OS) what went on between terminals and mainframes.

Each machine is connected via two cables: one to send instructions to the computer and one to receive output from the computer.
These cables are connected to the computer through a serial cable plugged into a Universal Asynchronous Receiver and Transmitter (UART).

Collapse
 
zcooper17 profile image
Zane

I'm also confused about both questions.