Atomic Operation Pread,pwirte
#include <unistd.h>
ssize_t pread (int fd, void *buf, size_t nbytes, off_t offset);//return value: Read the number of bytes, if the end of the file is returned 0, if an error returns 1
ssize_t pwrite (int fd,const void *buf, size_t nbytes, off_t offset);//return value: If the number of bytes written has been successfully returned, a return error of 1
Pread,pwirte, which is equivalent to calling Lseek and read or write sequentially, but cannot interrupt its location and read and write operations when calling Pread,pwrite, and cannot update the file pointer.
od-c file: View the actual contents of file
File sharing:
File descriptors: Each process has a record entry in the process table each record entry has an open File descriptor table (so it is necessary to copy the file descriptor), with each file Descriptor association: (a) the file descriptor flag. (b) A pointer to a file table entry.
File table: The kernel maintains a file table for all open files, with each file table entry containing: (a) file status flags (read, write, write-up, synchronous, non-blocking, etc.). (b) The offset of the current file. (c) A pointer to the V-node table entry for the file.
V node: Each open file (or device) has a V-node structure. Contains pointer information for a file type and functions that perform various operations on this file. For most files, the V node also contains the I node of the file (the index node). This information is read into memory from the disk when the file is opened, so all information about the file is quick to use. For example, the I node contains the owner of the file, the length of the file, the device where the file resides, a pointer to the actual data block used by the file on the disk, and so on.
The FCNTL function can change the nature of a file that has been opened.
int fcntl (int filedes, int cmd,....) ;
Cmd:
F_DUPFD Copy an existing file descriptor.
F_GETFD or F_SETFD get/Set file descriptor flag
F_GETFL or F_SETFL get/Set file status flag the state of mode in the Open function
F_getown or F_setown get/Set Async i/0 Permissions
F_getlk,f_setlk or f_setlkw get/set record lock
UNIX Environment Programming Learning-chapter 3 IO Read and write operations