为什么可以在Linux中删除/重命名打开的文件? [英] Why can one remove/rename open files in Linux?

查看:559
本文介绍了为什么可以在Linux中删除/重命名打开的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到,打开的文件不能在Windows中被删除/重命名,但可以在Linux中删除/重命名(默认情况下)。我想我理解Windows行为的原因。

现在我想知道为什么Linux允许重新打开/删除打开的文件?这个决定背后的设计原理是什么?什么是需要它的用例? 不同之处在于,linux在文件句柄而不是文件名上工作。只要文件句柄是有效的,你可以读写它。



在linux中重命名文件不会改变文件句柄。

一个非常有趣的用例是删除临时文件打开后。
这使得每个其他进程都无法访问这个文件,而拥有文件句柄的进程仍然可以读写。


I learned that open files can not be removed/renamed in Windows but can be removed/renamed in Linux (by default). I think I understand the reasons of the Windows behaviour.

Now I wonder why Linux allows remame/remove of open files ? What was the design rationale behind this decision ? What are the use cases when one need it ?

解决方案

the difference is that linux works on file handles rather than file names. as long as the file handle is valid you can read and write to it.

renaming a file in linux does not alter the file handle.

one very interesting use case is to delete temp files after opening them. this makes it impossible for every other process to access this file, while the process that owns the file handle can still read and write.

这篇关于为什么可以在Linux中删除/重命名打开的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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