From owner-freebsd-hackers@FreeBSD.ORG Sat Nov 27 19:07:16 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 5E68F106566C for ; Sat, 27 Nov 2010 19:07:16 +0000 (UTC) (envelope-from unixmania@gmail.com) Received: from mail-qw0-f54.google.com (mail-qw0-f54.google.com [209.85.216.54]) by mx1.freebsd.org (Postfix) with ESMTP id F1D3E8FC0A for ; Sat, 27 Nov 2010 19:07:15 +0000 (UTC) Received: by qwg8 with SMTP id 8so2207770qwg.13 for ; Sat, 27 Nov 2010 11:07:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=EdGZZ+gTGLBnIkmyNdbm+0298HYwF/FTVIvVh4X+pvs=; b=hL5AS/FepD6Tz01e5maT/S2NuJjNWNJ1hDboX+30clRvLHbkrjTGKl0cQvyt/8bKKK HI1znF3oinNgAF4d6L2/mJfLzDo5UaSZ6+YIg1QdAW2NTZjzj79XO/kMDdt6zu+1eHPG GLvW2wnuNaCLj85yN5VqU9z0A6ltNe7BPUJiA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=s3b9cbvTUmYtkcDUDdzPIqr/cGpCdjeFEaSxFMO5tA0DjmZOynv4F/rJ/70u3jzJRZ SwYC7po7aKmTHnXZAHMw6LGkR9pDy8F2JHkvn1x8DR+6A3C+mlIWJGpBTnUtQngZgfxT v77LqHMRXZA1xjNWkKfICNPH4Gpxsu8haFMCk= MIME-Version: 1.0 Received: by 10.229.82.10 with SMTP id z10mr3118768qck.98.1290884835060; Sat, 27 Nov 2010 11:07:15 -0800 (PST) Received: by 10.229.37.9 with HTTP; Sat, 27 Nov 2010 11:07:15 -0800 (PST) In-Reply-To: <4CF13D7A.4060904@FreeBSD.org> References: <4CEEC3BD.3080204@delphij.net> <4CF13D7A.4060904@FreeBSD.org> Date: Sat, 27 Nov 2010 17:07:15 -0200 Message-ID: From: "Carlos A. M. dos Santos" To: Dimitry Andric Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: FreeBSD-Hackers , 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:07:16 -0000 On Sat, Nov 27, 2010 at 3:18 PM, Dimitry Andric 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. =A0Is there a clean way to do this? > > Maybe your process could be the child of a parent which cleans up > afterwards? =A0(This is an analogy from real life. ;) #include #include #include #include #include static char filename[] =3D "/tmp/tmpfXXXXXX"; static int fd =3D 0; int main(void) { if ((fd =3D mkstemp(filename)) >=3D 0) { pid_t pid; if ((pid =3D fork()) > 0) { /* parent */ wait(NULL); printf("unlinking '%s'\n", filename); unlink(filename); return EXIT_SUCCESS; } else { /* child */ printf("file name is '%s'\n", filename); sleep(10); abort(); } } return EXIT_FAILURE; }