Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Nov 2010 20:16:54 +0100
From:      Dirk-Willem van Gulik <dirkx@webweaving.org>
To:        "Carlos A. M. dos Santos" <unixmania@gmail.com>
Cc:        FreeBSD-Hackers <freebsd-hackers@freebsd.org>, Dimitry Andric <dim@freebsd.org>, d@delphij.net
Subject:   Re: Is it possible to have file removed upon process exit?
Message-ID:  <2096C74B-62C5-4841-B05D-A3C55E759291@webweaving.org>
In-Reply-To: <AANLkTikH_uD1-yUe6KTufBvs9zRdQ%2BiMVQWcavBYRXU9@mail.gmail.com>
References:  <4CEEC3BD.3080204@delphij.net> <4CF13D7A.4060904@FreeBSD.org> <AANLkTikH_uD1-yUe6KTufBvs9zRdQ%2BiMVQWcavBYRXU9@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

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@freebsd.org> =
wrote:
>> On 2010-11-25 21:14, Xin LI wrote:
>>>=20
>>> 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?
>>=20
>> 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.=20

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.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2096C74B-62C5-4841-B05D-A3C55E759291>