Linux – Does two “virtual serial ports” exist in the virtual terminal implementation

linuxserial portterminalvirtual machine

The following image represents how a physical terminal (for example: VT100) was connected to a computer running Unix (for example: PDP-11):

enter image description here

Notice the components highlighted in blue, which shows that the terminal is connected to the computer through a serial port (the image says "UART" instead of "serial port"). So basically the terminal has a serial port that is connected though a wire to a serial port on the computer (the image also doesn't show a component for the terminal serial port).

You can change the baud rate for the serial port on the terminal side, also you can change the baud rate for the serial port on the computer side (see here).


Now the following image represents how a virtual terminal is implemented on a modern Linux/Unix machine:

enter image description here

Notice the components highlighted in blue, which shows that the terminal emulator is connected directly to the line discipline without using two "virtual serial ports".

Now my question is: is this image (the virtual terminal implementation) shows the entire components, or should a "virtual serial port" exist after the terminal emulator and another "virtual serial port" should exist before the line discipline?

If these two "virtual serial ports" do exist, can you also change their baud rate also?

I got these two images from here.

Best Answer

The line discipline controls handling of special characters (like software flow control, or characters generating signals) over the "line" (i.e., electrical wire in early unix systems). There are several possible line disciplines, and the tty driver calls the line discipline responsible for that tty.

So it makes absolutely no sense to have a "virtual serial port" in front of the line discipline. Not in the first picture, and not in the second picture.

The line discipline in turn just calls other parts of the kernel (the serial port driver (USB, UART, whatever), or the emulator for a virtual console, etc.), and also gets called by the corresponding driver if characters arrive. So in some sense this is a "virtual switch" where you can hook in different components.

But there's no pair of serial port drivers that somehow simulate sending a byte as bits over the line with a certain speed, and then reassembling it from bits as a byte. Because that would be unnecessary slow, and doesn't give a functionality.

Nevertheless, you can set the baud rate, amount of stop bits etc. for all tty's. These parameters are just ignored by drivers that don't need them, like the virtual console.