Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个创建文件并向其写入数据的 Windows 应用程序。应用程序已以独占方式打开文件,因此其他进程无法读取文件中的数据。
如果进程被杀死,则文件被删除。
如果进程被挂起并且文件的句柄被关闭(使用进程资源管理器),则文件被删除。
这一定是 Windows 的一个特性导致的,因为进程中没有更多的代码运行,因为它被杀死或挂起。
怎么会这样?什么类型的文件表现出这种行为?
没关系,我刚发现。
它FILE_FLAG_DELETE_ON_CLOSE在功能dwFlagsAndAttributes上CreateFile。
FILE_FLAG_DELETE_ON_CLOSE
dwFlagsAndAttributes
CreateFile
在问这个问题之前应该更努力地看:)
“关闭时删除”文件句柄。