一切皆文件--文件是什么--文件是对IO的最简抽象

引用《Linux Kernel Development》原书里面的一句话

in Unix, everything is a file.This simplifies the manipulation of data and devices into a set of core system calls: open(), read(), write(), lseek(), and close().

“UNIX文件本质上就是一大袋字节。” —— 《UNIX编程艺术》

说穿了,文件是对IO的最简抽象。

文件就是字节序列,系统中所有的输入输出其实都是通过UNIX I/O函数调用读写文件来实现的。

----深入理解计算机系统

https://www.zhihu.com/question/21040222/answer/96976318

在Unix中,任何可读/写也就是有I/O的设备,无论是文件,socket,驱动,在打开设备之后都有一个对应的文件描述符。Unix将对这些设备的读写简化在read/write中。

换言之,你只需要把打开的文件描述符传给这两个函数,操作系统内核知道如何根据这个文件描述符得到具体设备信息,内部隐藏了对各种设备进行读写的细节,所有这些对用户都是透明的,你只需要打开它,得到fd,再进行相应的操作就够了。

that a wide range of input/output resources  are simple streams of bytes exposed through the filesystem name space.[1]

https://www.cnblogs.com/feng9exe/p/8191921.html

原文地址:https://www.cnblogs.com/feng9exe/p/10221729.html