System-Level I/O
The input/output is the process of copying data between main memory and external devices such as disk drives, terminals, and networks. The input operation copies data from the I/O device to main memory, while the output operation copies data from main memory to the I/O device.
10.1 Unix I/O
A UNIX file is a sequence of M bytes: b0,b1,b2,b3 ... Bk... Bm-1.
All I/O devices, such as networks, disk box terminals, are modeled as files, and all inputs and outputs are executed as read and write to the corresponding file. This is an application interface that becomes UNIX I/O.
① Open File: An application declares that it wants to access an I/O device by requiring the kernel to open the appropriate file. The kernel returns a small, non-negative integer called a descriptor. It identifies this file in all subsequent operations on this file. The kernel logs all information about this open file. The application only needs to remember this identifier.
There are three open files at the beginning of each process of the UNIX shell: standard input (descriptor 0), standard output (descriptor 1), standard error (descriptor 2). Header file <unistd.h> defines constants Stdin_fileno, Stdout_fileno, Stderr_fileno, which are used instead of explicit descriptor values.
② changes the current file location. For each open file, the kernel maintains a file location K, which is initially 0. This file location is from
Information Security system design basics Eighth Week study notes