4 ms·
> * Temporary files. You can do all the file operations, and the file disappears on a reboot. It would be nice to be able to have a process tree own a temporar
by skissane 7y ago
> * Temporary files. You can do all the file operations, and the file disappears on a reboot.
It would be nice to be able to have a process tree own a temporary file, such that when the last process in the tree exits (not necessarily the process which created the file), the file is automatically deleted, rather than having to wait for the next reboot.
- Animats 7y agoThis is mostly about defining behavior for the bad cases - program abort and system restart. Those are classically undefined behavior, which causes problems.
- vbezhenar 7y agoCan't you create file, unlink it and then fork as much as necessary? I think that OS will maintain reference counter for that inode and will delete it when all processes will close that handle (explicitly or implicitly with exit).
- IshKebab 7y agoSadly not because then the file doesn't have a filename, and there are a lot of things that only work with file names, not descriptors. Even basic stuff like std::fstream needs a filename. Yes there are workarounds (library extensions, signals, /proc/fd, etc.) But you'd think a basic function like "delete this file when this process exits" wouldn't be too hard.
- TeMPOraL 7y agoI would prefer it to not be the default; it's sometimes useful to keep temporary files in the event of a process crash, especially on a server that would then immediately restart said process. I had such a case very recently, and was thankful for the existing behavior of tmp files.
- skissane 7y agoRather than delete the file straight away, put it in a “trash can” or “recycle bin”. A background process deletes files from “trash can” at a later date. It could normally give them a grace period (e.g. 7 days, configurable) but the files could be deleted early if storage space is running low. The same feature could be used to provide undelete for non-temporary files too.
- JetSpiegel 7y agomktemp is enough for this.
- the8472 7y agoIf you use O_TMPFILE and pass file descriptors to child processes instead of paths this is possible. It's allocated on disk but never given a directory entry, so it gets deleted once the last process holding an fd terminates.