Linux确保文件的内容在close()后被刷新到光盘上? [英] Does Linux guarantee the contents of a file is flushed to disc after close()?

查看:564
本文介绍了Linux确保文件的内容在close()后被刷新到光盘上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 close() fclose()来关闭文件时,Linux保证该文件被写回到(永久)光盘?



我的意思是,如果 close()返回0,然后立即电源失败,先前写入的数据保证持久,即是持久的?

fsync()

我找不到任何东西,使得任何索赔的方式或另一个目前。






问题2:

如果 close()确实隐式地做了一个 fsync(),有没有告诉它的方法?

解决方案

从< man 2 close


成功关闭并不能保证数据已经被成功保存到磁盘
,因为
内核推迟写入。



<手册页说,如果你想确保你的数据在磁盘上,你必须自己使用fsync()。


When a file is closed using close() or fclose() (for example), does Linux guarantee that the file is written back to (persistent) disc?

What I mean is, if close() returns 0 and then immediately afterwards the power fails, are previously written data guaranteed to persist, i.e. be durable?

The fsync() system call does provide this guarantee. Is closing a file also sufficient?

I can't find anything which makes any claim one way or another at the moment.


Question 2:

If close() does implicitly do an fsync(), is there a way of telling it not to?

解决方案

From "man 2 close":

A successful close does not guarantee that the data has been successfully saved to disk, as the kernel defers writes.

The man page says that if you want to be sure that your data are on disk, you have to use fsync() yourself.

这篇关于Linux确保文件的内容在close()后被刷新到光盘上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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