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:
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
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:
gnome-terminalis executed, it will create a file representing a serial port in the
/dev/ptsdirectory (let's say the file name is
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
bashwould start reading from
gnome-terminalwants to send data to
bash, it would write this data to
bashwould read this data from
bashwants to send data to
gnome-terminal, it would write this data to
gnome-terminalwould read this data from
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.