在Linux上是否关闭()调用的fsync()? [英] Does close() call fsync() on Linux?

查看:2117
本文介绍了在Linux上是否关闭()调用的fsync()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们调用接近(小于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()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆