In class, professor mentions that there are Stream and Storage devices. I mean to ask about Stream devices. I've also heard the terminology character devices.
On a Linux VM, the corresponding terminal devices can be seen via the proc
file system:
$ ls -l /proc/$$/fd
total 0
lrwx------ ... ... ... 0 -> /dev/tty1
lrwx------ ... ... ... 1 -> /dev/tty1
lrwx------ ... ... ... 10 -> /dev/tty1
lrwx------ ... ... ... 2 -> /dev/tty1
It seems that stdin, stdout, stderr all point to the same device, and zsh
maintains fd 10
for access to the terminal.
I'm wondering specifically about how the terminal works and programs like shell interact with it, since it seems that programs like cat
only receive input on <Enter>
when reading stdin. Something curious I found is that you can also write to stdin much like stdout, so I am wondering how the offsets are maintained, since these devices do not have a valid lseek.
Here is an example:
#include <unistd.h>
int main () {
write(STDIN_FILENO, "hello\n", 6);
return 0;
}
My question is really: what is managing the data you type into your computer and you see on your screen, if it is not "Storage"? I am asking about the concept of a "Stream" device and the above are examples.