Perplexity about TTY and PTY

Hello Guys, i'm trying to understand the usage of Pseudoterminal but it's really hard even to explain my doubts.

A Pseudoterminal is a pair: Master and Slave in order to create a bi-directional channel between two procecces.

Looking at this image: https://en.wikipedia.org/wiki/Pseudoterminal#/media/File:Termios-script-diagram.svg

I don't understand, for example, why do we need the PTM (pseudoterminal Master)?. i mean, we could even link the script process directly to the slave to allow the comunication between the two processes.

Another perplexity is: Pseudoterminal and Terminal Emulator is related each other? I mean, does a terminal emulator emulates a real Terminal (a phisical terminal) using the Slave and Master pair? the question arises from the PS' output:

1
2
3
4
5
┌──(vitto㉿Main)-[/mnt/c/Users/Vitto]
└─$ ps
  PID TTY          TIME CMD
    9 pts/0    00:00:00 bash
   35 pts/0    00:00:00 ps


Why bash is associated with a Slave? (pts/0)?
Im using a WSL 2.0 from windows environment.

I hope that you understand my thoughts, because im really confused about this topic right now.
Thank you all in advice!
Yeah, the article doesn't say very much, and is implicitly misleading.

Every process gets a terminal. It uses this for I/O. However, there's only one terminal in a process group, owned by the group leader.

Someone asked about creating daemons recently. Well, one of the things a typical daemon does is discard it's terminal. It's not unusual to see daemons in development writing log messages down a network endpoint because fd(1), normally stdout had been re-bound to a tcp socket. So a deamon will only have terminal if the client functionality requires it.

If you want the server-side to run in a different context, it'll typically loose its terminal, and it has to create a new one. A typical example is using ssh to run sudo. If you want to see how it's done, check out openssh's source, it's pretty obvious once you find the code (follow the -t option).
Registered users can post here. Sign in or register to post.