Fsync vs system call

I would like to ask a fundamental question about when it is useful to use a system call like fsync. I am starting, and I always got the impression that writing is enough to write to a file, and samples that use writing are actually written to the file at the end.

So what is the purpose of a fsync type system call?

Just to provide some background, I use the Berkeley DB library version 5.1.19, and there is a lot of talk about the cost of fsync () and just writing. That is why I am wondering.

+3
source share
1 answer

Think of it as a buffering layer.

C, fopen fprintf, , C.

fflush, , C ( ).

, , , , . .

, fsync, , .

:

fprintf (myFileHandle, "something\n");  // output it
fflush (myFileHandle);                  // flush to OS
fsync (fileno (myFileHandle));          // flush to disk

fileno - , int FILE*, fsync .

, , .

, . , , . , . ! , . , , ACID: -)

+8

All Articles