fflush和fsync的联系和区别
1.出处
fflush是libc.a中提供的方法,
fsync是系统提供的系统调用。
2.原形
fflush接受一个参数FILE *.
fflush(FILE *);
fsync接受的时一个Int型的文件描述符。
fsync(int fd);
3.功能
fflush:是把C库中的缓冲调用write函数写到磁盘[其实是写到内核的缓冲区]。
fsync:是把内核缓冲刷到磁盘上。
c库缓冲-----fflush---------〉内核缓冲--------fsync-----〉磁盘
另外关于内核缓冲,标准库缓冲和用户空间缓冲的说法见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, fgets and fputs, the data is usually copied twice: once between the kernel and the standard I/O buffer (when the corresponding read or writeis issued) and again between the standard I/O buffer and our line buffer.
            
 
作者:beanmoon            
 
出处:http://www.cnblogs.com/beanmoon/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
该文章也同时发布在我的独立博客中-豆月博客。
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号