zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    多校省选模拟33 C
    省选测试47 T2宝石(P5401 [CTS2019]珍珠) 题解
    省选测试39
    省选测试38
    省选测试37
    自嗨测试赛4
    自嗨测试赛3
    自嗨测试赛2
    自嗨测试赛1
    树状数组 学习笔记
  • 原文地址:https://www.cnblogs.com/beanmoon/p/2735583.html
Copyright © 2011-2022 走看看