Is there a way to create/access a temporary file (e.g. GetTempFileName) and delete it right after the process has been killed/terminated? I know it is possible with the JobAPI to terminate all child processes but I was wondering if you could use such a method with a file.
1
votes
@DevSolar: There is no SIGINT or SIGTERM on Windows. This is fairly unrelated. Anyway, David Heffernan already posted the correct answer, that works, regardless of how a process is terminated.
- IInspectable
@DevSolar: signal.h allows developers to port code that relies on signals. It does not magically introduce signals into Windows. This is purely a software implementation, attempting to meet ANSI compatibility (SIGILL and SIGTERM are not generated on Windows, for example, neither is SIGINT). Do I want to reconsider my statement? Considering that the documentation agrees with me, I don't have much of an incentive, now do I?
- IInspectable
@IInspectable: Again I am stumped by Microsoft's failures to properly support standards. Retracting my comments.
- DevSolar
@DevSolar Windows does not purport to support POSIX, or whatever standard you feel it should support.
- David Heffernan
@IInspectable: minor quibble, for the record - SIGINT is in fact emulated by the Microsoft C runtime (but only for console applications). It isn't supported, but last time I checked at least the emulation was still in place. If you register a SIGINT handler, it will run when control-C is pressed. (The reason it isn't supported is that it runs in the "wrong" thread, violating the expectations of UNIX programmers.)
- Harry Johnston
1 Answers
4
votes
Pass the FILE_FLAG_DELETE_ON_CLOSE flag to CreateFile and the file will be deleted when all of its handles are closed. The documentation says:
The file is to be deleted immediately after all of its handles are closed, which includes the specified handle and any other open or duplicated handles.