Open File Deletion

Discussions center on OS behaviors for deleting or modifying files still open via file descriptors, contrasting Unix-like systems (unlink keeps file until all FDs closed) with Windows (prevents deletion), including issues with sharing FDs, locking, and portability.

📉 Falling 0.4x DevOps & Infrastructure
2,973
Comments
19
Years Active
5
Top Authors
#3171
Topic ID

Activity Over Time

2008
3
2009
24
2010
45
2011
56
2012
76
2013
93
2014
86
2015
117
2016
139
2017
155
2018
197
2019
191
2020
335
2021
208
2022
327
2023
325
2024
318
2025
262
2026
16

Keywords

FD e.g InterruptibleChannel.html GC OP InterruptibleChannel java.base HTTP POSIX IPC file open files closing close locks proc windows process shared

Sample Comments

jimbobthrowawy May 18, 2024 View on HN

Shouldn't this be possible by looking inside of /proc/ if the file's still open?

pjmlp Nov 27, 2021 View on HN

Including if the file is already being used by another process, what could go wrong.

JdeBP Feb 3, 2019 View on HN

There is no guarantee of that if one does retain the open file descriptor.

nikbackm Nov 2, 2017 View on HN

Wouldn't fopen and friends also have issues when locking isn't working properly?

vidarh Jul 15, 2014 View on HN

Even if you have opened it, you have no guarantee that the file descriptor has not been closed since. Yes, that would be stupid of the user of the library, but many security lapses happens because people makes stupid assumptions. Code to close all file descriptors on fork for example is fairly common, so you can not safely assume that the file descriptor remains valid.

BubRoss Feb 20, 2020 View on HN

It's the right thing to give an error that some process has the file open but never tell you which process that is?

neolog Jun 25, 2021 View on HN

What do they do about open file descriptors?

Gigachad Feb 5, 2023 View on HN

How would you pass an open file by value? What happens when one copy tries to close the file while another still has it open?

1718627440 Oct 15, 2025 View on HN

This is essentially the same as using unlink on Linux, because this also keeps the file around until it is open.

SCHiM May 6, 2022 View on HN

Off topic: what type of error can occur when closing a file? Is it somehow possible that the kernel denies your request, and forces your handle to stay open?