Force the system cache to be written to the file sync and Fsync functions, fflush and Fsync and distinguish between __ functions

Source: Internet
Author: User

The traditional U N I x implementations have buffer memory in the kernel, and most disk I/O is done through caching. When the data is written
To a file, the data is typically copied from the kernel to the cache, and if the cache is not already full, it is not queued to the output
Queue, instead of waiting for it to be filled, or when the kernel needs to reuse the cache to hold other disk block data, and then row the cache
Into the output queue, and then when it arrives at the head of the team, the actual I/O operation is performed. This type of output is called deferred write
(Delayed Write) (Bach(1 9 8 6) The 3rd chapter discusses in detail the deferred writing). Delayed write reduces disk read and write times, but
Chapter 4th Documents and Directories 8 7
Download
It reduces the speed at which files are updated so that the data you want to write to a file is not written to disk for a while. When
This delay may result in the loss of the file update content when the system fails. In order to ensure the actual file system on disk and slow
The consistency of the stored content, the U n I x system provides the S Y N C and F S y N C two system call functions.
#include <unistd.h>
void sync (void);
int Fsync (intf l e d e s);
Return: If the success is 0, if the error is-1
s y n c simply queues the cache of all modified blocks into the write queue, and then returns, which does not wait for the actual I/O operation to end.
The system daemon process (usually called U P d a T e) typically calls the S Y n C function every 3 0 seconds. This ensures a regular refresh within
Block cache of cores. The command s y N C (1) also calls the S Y n C function.
function f S y n C refers only to a single file (specified by the file descriptor F i e d e s), it waits for I/O to end, and then returns. F S y N C can
For applications such as databases, which ensure that the modified blocks are immediately written to disk. Compare F S y n C and O s y N C standard
Chi (see 3.1 3). When you call F S y n C, it updates the contents of the file, and for o _ s y n C, the file is called W r i t e each time
function, the contents of the file are updated.


Fflush and Fsync and the difference between
[ZZ] Http://blog.chinaunix.net/u2/73874/showart_1421917.html

1. Provider Fflush is the method provided in LIBC.A, Fsync is a system-provided call. 2. Prototype Fflush accepts a parameter file *. Fflush (FILE *); Fsync accepts a file descriptor of type int. Fsync (int fd); 3. Function Fflush: is the buffer call in C library write function to disk [is actually written to the kernel of the buffer]. Fsync: The kernel is slowly flushed to disk.

C library buffering-----fflush---------kernel buffering--------fsync-----Disk

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.