Connection and difference between fflush and fsync

Source: Internet
Author: User

1. Source

Fflush is the method provided in libc.,

Fsync is a system call provided by the system.

2. Prototype

Fflush accepts a parameter file *.

Fflush (File *);

Fsync accepts an int-type file descriptor.

Fsync (int fd );

3. Functions

Fflush: writes the buffer calling write function in the C library to the disk [actually writing the buffer to the kernel].

Fsync: fl the kernel buffer to the disk.

C Library Buffer ----- fflush ---------> kernel buffer -------- fsync -----> Disk

For more information about Kernel buffering, standard library buffering, and user space buffering, see apue 5.14:

One inefficiency inherent in the standard I/O Library is the amount of data copying that takes place. When we use the line-at-a-time functions,FgetsAndFputs, The data is usually copied twice: once between the kernel and the standard I/O buffer (when the correspondingReadOrWriteIs issued) and again between the standard I/O buffer and our line buffer.

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.