From owner-freebsd-hackers@FreeBSD.ORG Sat Nov 27 19:17:32 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CF111106566B for ; Sat, 27 Nov 2010 19:17:32 +0000 (UTC) (envelope-from dirkx@webweaving.org) Received: from schier.webweaving.org (schier.webweaving.org [213.207.101.177]) by mx1.freebsd.org (Postfix) with ESMTP id 675C28FC08 for ; Sat, 27 Nov 2010 19:17:31 +0000 (UTC) Received: from [10.11.0.244] (5356CBE6.cm-6-7d.dynamic.ziggo.nl [83.86.203.230]) (authenticated bits=0) by schier.webweaving.org (8.13.8/8.13.8) with ESMTP id oARJEDvd069759 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Sat, 27 Nov 2010 20:14:14 +0100 (CET) (envelope-from dirkx@webweaving.org) Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: text/plain; charset=us-ascii From: Dirk-Willem van Gulik In-Reply-To: Date: Sat, 27 Nov 2010 20:16:54 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: <2096C74B-62C5-4841-B05D-A3C55E759291@webweaving.org> References: <4CEEC3BD.3080204@delphij.net> <4CF13D7A.4060904@FreeBSD.org> To: "Carlos A. M. dos Santos" X-Mailer: Apple Mail (2.1082) X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-3.0 (schier.webweaving.org [213.207.101.177]); Sat, 27 Nov 2010 20:14:16 +0100 (CET) Cc: FreeBSD-Hackers , Dimitry Andric , d@delphij.net Subject: Re: Is it possible to have file removed upon process exit? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Nov 2010 19:17:32 -0000 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 = 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.