1.\" $NetBSD: pidfile.3,v 1.8 2002/10/01 19:36:30 wiz Exp $ 2.\" $DragonFly: src/lib/libutil/pidfile.3,v 1.2 2005/05/22 17:48:57 liamfoy Exp $ 3.\" 4.\" Copyright (c) 1999 The NetBSD Foundation, Inc. 5.\" All rights reserved. 6.\" 7.\" This code is derived from software contributed to The NetBSD Foundation 8.\" by Jason R. Thorpe. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 3. All advertising materials mentioning features or use of this software 19.\" must display the following acknowledgement: 20.\" This product includes software developed by the NetBSD 21.\" Foundation, Inc. and its contributors. 22.\" 4. Neither the name of The NetBSD Foundation nor the names of its 23.\" contributors may be used to endorse or promote products derived 24.\" from this software without specific prior written permission. 25.\" 26.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36.\" POSSIBILITY OF SUCH DAMAGE. 37.\" 38.Dd June 5, 1999 39.Dt PIDFILE 3 40.Os 41.Sh NAME 42.Nm pidfile 43.Nd write a daemon pid file 44.Sh LIBRARY 45.Lb libutil 46.Sh SYNOPSIS 47.In sys/types.h 48.In libutil.h 49.Ft int 50.Fn pidfile "const char *basename" 51.Sh DESCRIPTION 52.Fn pidfile 53writes a file containing the process ID of the program to the 54.Pa /var/run 55directory. 56The file name has the form 57.Pa /var/run/basename.pid . 58If the 59.Ar basename 60argument is NULL, 61.Nm 62will determine the program name and use that instead. 63.Pp 64The pid file can be used as a quick reference if 65the process needs to be sent a signal. 66When the program exits, the pid file will be removed automatically, unless 67the program receives a fatal signal. 68.Pp 69Note that only the first invocation of 70.Nm 71causes a pid file to be written; subsequent invocations have no effect 72unless a new 73.Ar basename 74is supplied. 75If called with a new 76.Ar basename , 77.Fn pidfile 78will remove the old pid file and write the new one. 79.Sh RETURN VALUES 80.Fn pidfile 81returns 0 on success and -1 on failure. 82.Sh SEE ALSO 83.Xr atexit 3 84.Sh HISTORY 85The 86.Nm 87function call appeared in 88.Nx 1.5 . 89.Sh BUGS 90.Fn pidfile 91uses 92.Xr atexit 3 93to ensure the pidfile is unlinked at program exit. 94However, programs that use the 95.Xr _exit 2 96function (for example, in signal handlers) 97will not trigger this behaviour. 98