General steps for file programming:
1. Open/Create File
2. Read/write files
3. Close the file
Text from Advanced Programming in Unix Environment
Static files: all files stored on disk
Dynamic file: After open opens the file, the Linux kernel generates a structure.
Linux kernel structure: fd
information node
buf is used to store content, which is essentially memory.
File read and write operations actually read the dynamic file in the memory. When operating the dynamic file, it will be written to the disk only after close closes the file. Therefore, the file must be closed after opening the file.
Introduction to file descriptors
int n_read=read(0,buf,5);
int n_write=write(1,buf,5);
0 - corresponds to standard input
1——corresponds to standard output
2——Corresponding standard error
Linux file management description
To use the API related to Linux file programming, click the link below
x file management brief introduction