当我们调用接近(小于FD>),它自动执行 FSYNC()同步到物理介质?
When we call close(<fd>), does it automatically do fsync() to sync to the physical media?
推荐答案它没有。调用的close()并不能保证内容是在磁盘上的操作系统可能会推迟写入。
It does not. Calling close() DOES NOT guarantee that contents are on the disk as the OS may have deferred the writes.
作为一个方面说明,经常检查的返回值的close()。它会让你知道任何递延错误到这一点的。如果你想以确保内容是在磁盘上始终调用 FSYNC()并检查其返回值也是如此。
As a side note, always check the return value of close(). It will let you know of any deferred errors up to that point. And if you want to ensure that the contents are on the disk always call fsync() and check its return value as well.
有一点要记住的是后备存储是什么。有迹象表明可能会做内部写管理延迟和内容在某些情况下会丢失(尽管新的存储介质的设备通常具有超级电容器以prevent这一点,或者方法来禁用此功能)的设备。
One thing to keep in mind is what the backing store is. There are devices that may do internal write deferring and content can be lost in some cases (although newer storage media devices typically have super capacitors to prevent this, or ways to disable this feature).
更多推荐
在Linux上是否关闭()调用的fsync()?
发布评论