Skip to content

Files

Open file: The value returned by an open call is termed a file descriptor and is essentially an index into an array of open files kept by the kernel per process.

默认的三个 file descriptor:

Standard In stdin   0   Input from the keyboard
Standard Out    stdout  1   Output to the console
Standard Error  stderr  2   Error output to the console

如何 list 当前的 file descriptors:

ls -l /proc/$$/fd
# 其中 $$ will give the process ID of the currently running shell. 同 ps

BTW, You can not delete /proc since they are not files. /proc is mounted using the procFS, which is not a real filesystem. Instead the contents are generated the moment you try to read from them. This also means it is not using any disk space at all. (So there is no reason in trying to delete it).

注意 特别的路径比如 /dev/ 系列 To provide the abstraction to user-space, the kernel provides a file-interface via what is generically termed a device layer. Physical devices on the host are represented by a file in a special file system such as /dev. Device files are abstractions of standard devices that applications interact with via I/O system calls. In UNIX-like systems, so-called device-nodes have what are termed a major and a minor number, which allow the kernel to associate particular nodes with their underlying driver. The major number tells you which driver is used to access the hardware. The minor number is used by the driver to distinguish between the various hardware it controls.

The pipe is an in-memory buffer that connects two processes together. file descriptors point to the pipe object, which buffers data sent to it (via a write) to be drained (via a read).