In Linux, a Terminal is associated with a Shell. The Terminal send input to the Shell (for example: pwd), and the Shell send the output back to the Terminal (for example: /home/paul).
This diagram shows the relationship between a Terminal and a Shell (assume that the Terminal I am using is gnome-terminal, and the Shell is bash):
Now what I want to know is what mechanism does the Terminal and the Shell use to exchange data. This is what I think happens:
- When
gnome-terminalis executed, it will create a file representing a serial port in the/dev/ptsdirectory (let's say the file name is/dev/pts/0). gnome-terminalwill then execute the Shell associated with it (for example:bash), and will pass it the pts file name (the pts file name can be passed through the command line arguments for example).- Now both
gnome-terminalandbashwould start reading from/dev/pts/0. - When
gnome-terminalwants to send data tobash, it would write this data to/dev/pts/0, andbashwould read this data from/dev/pts/0. - When
bashwants to send data tognome-terminal, it would write this data to/dev/pts/0,andgnome-terminalwould read this data from/dev/pts/0.
This diagram shows what I just explained:
Am I correct in my understanding?
Note: of course the pts file could be a tty file if we were using virtual terminals (i.e. when we are not using a GUI), but the logic would still be the same.

