Apue,tlpi reading notes--linux IO related __linux

Source: Internet
Author: User

File descriptor: A non-negative integer that is the index of the kernel Open file table.

Each process has its own file descriptor, the kernel maintains an open file table, a different descriptor points to the kernel File open table, and points to the actual location of the file on the I-node table.

Linux System File IO functions ( details can be used in the Linux shell man-a + function name query or query on the Man-online ):

Fd=open (Pathname,flags,mode);

Numread=read (Fd,buffer,count),//reads up to count bytes, returns the number of bytes read

Numwritten=write (Fd,buffer,count);

Status=close (FD);

Currpos=lseek (fd,offset,whence)//Return file New file offset

int ioctl (int fildes, int request, .../*arg);//control of a streaming device


Flags=fcntl (Fd,cmd,...) //File Control operations Newfd=dup (OLDFD)//The creation of a copy of a file descriptor in the Process file descriptor Table newfd=dup2 (OLDFD,NEWFD)//can operate on an existing FD. If it is turned on, the Newfd=dup3 (oldfd,newfd,flags) is turned off, the Pread,pwrite function reads and writes at the offset parameter, does not change the file offset, and is suitable for multi-threaded read-write Readv,writev (distributed input, centralized output) input/ Output to the buffer pointed to by the Iovec pointer array truncate (PATHNAME,LENGTH), ftruncate (fd,length) Truncate the file, set the file size to length, lose more than fill (cause empty) set fcntl in open or o_ Nonblock flag, for non-blocking io large file io,open64,fopen64,lseek64 et cetera/dev/fd view file descriptor (all Linux will react in file form) mkstemp (template), file* tmpfile (void) To create a temporary file. The latter creates a unique temporary file name, which is automatically deleted after the file stream is closed

C Standard library:
Packaging for reading and writing to the underlying system
Specific introduction can refer to: C standard IO


File IO buffering

The Read,write operation disk does not have direct disk access, but rather copies data between the user space buffer and the kernel buffer.

Select the appropriate buffer size based on the size of read and write data to optimize read and write efficiency

C Standard library buffer: setvbuf set buffer 1. no buffering; 2. Line buffering; 3. Full buffering; fflush Flushing buffer.

Fsync () Call buffer data flush to disk associated with FD

Fdatasync () is similar to Fsync (), but forces the file to be in the synchronized IO data integrity completion State

Found on the Internet:

Synchronized IO Data integrity completion: Ensure that an update to a file passes enough information (partial file metadata) to disk to facilitate subsequent access to the data.

Synchronized IO file Integrity completion: Ensure that all information (all file metadata) is passed to disk for one update to the file, even if some of the subsequent operations on the file data are not needed.


Sync is to update all the kernel buffers that contain the file information flushed to disk

Posix_advise provides an IO mode proposal for the kernel, details man

File's O_direct flag bypasses buffer Direct IO



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.