Difference between fflush and fsync
2014-02-27 07:43
337 查看
今天做APUE的习题,对fflush和fsync的区别不甚了解,google了一下,找到了一个回答备忘下:
原文链接:http://stackoverflow.com/questions/2340610/difference-between-fflush-and-fsync
on FILE* , it just flushes the internal buffers in the
your application out to the OS.
on a lower level, it tells the OS to flush its buffers to the physical media.
OSs heavily caches data you write to a file. If the OS enforced every write to hit the drive, things would be very slow. fsync(among other things)
allows you to control when the data should hit the drive.
Furthermore, fsync/commit works on a file descriptor. It has no knowledge of a FILE* and can't flush its buffers. FILE* lives in your application, file descriptors lives in the OS kernel, typically.
还有一个链接,写的也很详细:http://blog.chinaunix.net/uid-1911213-id-3412851.html
原文链接:http://stackoverflow.com/questions/2340610/difference-between-fflush-and-fsync
fflush()works
on FILE* , it just flushes the internal buffers in the
FILE*of
your application out to the OS.
fsyncworks
on a lower level, it tells the OS to flush its buffers to the physical media.
OSs heavily caches data you write to a file. If the OS enforced every write to hit the drive, things would be very slow. fsync(among other things)
allows you to control when the data should hit the drive.
Furthermore, fsync/commit works on a file descriptor. It has no knowledge of a FILE* and can't flush its buffers. FILE* lives in your application, file descriptors lives in the OS kernel, typically.
还有一个链接,写的也很详细:http://blog.chinaunix.net/uid-1911213-id-3412851.html
相关文章推荐
- The difference between GDI+ and GDI
- what is the difference between definition and declaration in c
- Difference between hash() and id()
- Difference between pointer variable and reference variable in C++
- Difference between Cache and Buffer
- [WPF]The differences between Text Box and Text Block in Blend
- Difference between Properties and Attributes in JavaScript
- The differences between BLOB and TEXT
- What is the basic difference between NSTimer, NSTask, NSThread and NSRunloop ?
- Difference between break and return
- Differences between the C Locale and the C++ Locales
- Difference Between Logical and Physical Database Model
- the-difference-between-REST-and-SOAP
- Is punishment necessary to help children learn the difference between right and wrong?
- Difference between Statement and preparedStatement
- Difference between clone and copy
- The difference between Spring Tool Suite and Spring IDE
- The difference between Proxy and CGLIB
- Difference Between Class.forName() and ClassLoader.loadClass()
- Differences between volume and partition(from wiki)