Terminal vs shell


Terminal is handled by the parent process of shell
$ ps -o ‘cmd=’ -p $(ps -o ‘ppid=’ -p $$) give the parent process in these circumstances:
output when SSH: sshd: rio@pts/0
output when WSL: /init ro

The flow:
Physical Line: terminal – modem – – modem – UART – tty driver – application
UART: Universal Asynchronous Receiver and Transmitter
Virtual Console: keyboard and monitor – Terminal Emulator – /dev/tty*
fullscreen controlled by CtrlAltF*,
/dev/tty1-6 are supported by kernel directly
SSH: ssh client – sshd – ptmx – pts/* – shell forked by sshd
Terminal Window: the ones launched in a window system:
same flow as SSH, just replace ssh+sshd with the grphaic terminal since no network involved.
WSL: $tty1 pts/0, therefore, similar to Terminal Window

Terminal handles the input and output of shell.
Input: e.g. translate arrow keys, translate ctrlC to SIGINT
Output: application -> tty driver in kernel -> UART
Each tty driver, e.g. ttyS0, server multiple applications
$ lsof /dev/pts/1 tells stdin stdout stderr binded to this tty as FD 0u 1u 2u
tty keeps record of Foreground process group
Reference: https://segmentfault.com/a/1190000009082089

Previous Post
Comments are closed.
%d bloggers like this: