Is it possible to have file removed upon process exit?
Dirk-Willem van Gulik
dirkx at webweaving.org
Sat Nov 27 19:17:32 UTC 2010
Op 27 nov 2010, om 20:07 heeft Carlos A. M. dos Santos het volgende geschreven:
> On Sat, Nov 27, 2010 at 3:18 PM, Dimitry Andric <dim at freebsd.org> wrote:
>> On 2010-11-25 21:14, Xin LI wrote:
>>>
>>> For certain applications it is sometimes desirable to (e.g. for unix
>>> domain sockets) have file removed when the process quit, regardless
>>> whether the process is quit cleanly. Is there a clean way to do this?
>>
>> Maybe your process could be the child of a parent which cleans up
>> afterwards? (This is an analogy from real life. ;)
Another option, depending on the situation is to fopen()/open() the file - and as soon as that is successfully done by all involved - have the creating process delete it.
The libc call tmpfile(3) basically does just this.
Also have a look at atexit(3) - though it is not called in messy sitations - the fork/waiting for a signal is propably about as robust as it gets. Another variation is something like 'open all the files/sockets you need, fork and have the parent delete them - while the child runs -then wait'.
Dw.
More information about the freebsd-hackers
mailing list