Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

option for guaranteed auto cleanup using file descriptor trick #10

Open
timotheecour opened this issue Nov 30, 2018 · 1 comment
Open
Assignees

Comments

@timotheecour
Copy link

this answer uses a nice trick to guarantee auto cleanup:

tmpfile=$(mktemp /tmp/abc-script.XXXXXX)
exec 3>"$tmpfile"
rm "$tmpfile"
: ...
echo foo >&3

the cleanup would happen even if a crash happens (or, say, a quit):

When it gets closed (which the kernel does automatically when the process exits) the filesystem deletes the file

the same trick could be used (as option!) in tempfile API

@timotheecour timotheecour changed the title option for guaranteed auto cleanup option for guaranteed auto cleanup using file descriptor trick Nov 30, 2018
@ba0f3 ba0f3 self-assigned this Nov 30, 2018
@ba0f3
Copy link
Collaborator

ba0f3 commented Nov 30, 2018

thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants