rename() 是原子的吗? [英] Is rename() atomic?

查看:62
本文介绍了rename() 是原子的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过实验检查这一点,也无法从手册页中收集到它.

I am not being able to check this via experiments and could not gather it from the man pages as well.

假设我有两个进程,一个是将文件 1 从目录 1 移动(重命名)到目录 2.假设同时运行的另一个进程将 directory1 和 directory2 的内容复制到另一个位置.复制是否有可能以这样的方式发生,即目录 1 和目录 2 都将显示文件 1 - 即目录1 在移动之前被复制,目录2 在移动之后被第一个进程复制.

Say I have two processes, one moving(rename) file1 from directory1 to directory2. Say the other process running concurrently copies the contents of directory1 and directory2 to another location. Is it possible that the copy happens in such a way that both directory1 and directory2 will show file1 - i.e directory1 is copied before the move and directory2 after the move by the first process.

基本上是 rename() 是一个原子系统调用?

Basically is rename() is an atomic system call?

谢谢

推荐答案

是和否.

rename() 是原子的,假设操作系统没有崩溃.它不能被任何其他文件系统操作拆分.

rename() is atomic assuming the OS does not crash. It cannot be split by any other filesystem op.

如果系统崩溃,您可能会看到一个 ln() 操作.

If the system crashes you might see a ln() operation instead.

另请注意,在网络文件系统上操作时,如果操作成功,您可能会收到 ENOENT.本地文件系统无法对您执行此操作.

Also note, when operating on a network filesystem, you might get ENOENT when the operation succeeded successfully. Local filesystem can't do that to you.

这篇关于rename() 是原子的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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