1*86f9d4cdStedu.\" $OpenBSD: pidfile.3,v 1.7 2013/06/05 03:40:26 tedu Exp $ 27ed310cbSjakob.\" $NetBSD: pidfile.3,v 1.2 2001/04/12 22:34:31 sommerfeld Exp $ 37ed310cbSjakob.\" 47ed310cbSjakob.\" Copyright (c) 1999 The NetBSD Foundation, Inc. 57ed310cbSjakob.\" All rights reserved. 67ed310cbSjakob.\" 77ed310cbSjakob.\" This code is derived from software contributed to The NetBSD Foundation 87ed310cbSjakob.\" by Jason R. Thorpe. 97ed310cbSjakob.\" 107ed310cbSjakob.\" Redistribution and use in source and binary forms, with or without 117ed310cbSjakob.\" modification, are permitted provided that the following conditions 127ed310cbSjakob.\" are met: 137ed310cbSjakob.\" 1. Redistributions of source code must retain the above copyright 147ed310cbSjakob.\" notice, this list of conditions and the following disclaimer. 157ed310cbSjakob.\" 2. Redistributions in binary form must reproduce the above copyright 167ed310cbSjakob.\" notice, this list of conditions and the following disclaimer in the 177ed310cbSjakob.\" documentation and/or other materials provided with the distribution. 187ed310cbSjakob.\" 197ed310cbSjakob.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 207ed310cbSjakob.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 217ed310cbSjakob.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 227ed310cbSjakob.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 237ed310cbSjakob.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 247ed310cbSjakob.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 257ed310cbSjakob.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 267ed310cbSjakob.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 277ed310cbSjakob.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 287ed310cbSjakob.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 297ed310cbSjakob.\" POSSIBILITY OF SUCH DAMAGE. 307ed310cbSjakob.\" 31*86f9d4cdStedu.Dd $Mdocdate: June 5 2013 $ 327ed310cbSjakob.Dt PIDFILE 3 337ed310cbSjakob.Os 347ed310cbSjakob.Sh NAME 357ed310cbSjakob.Nm pidfile 367ed310cbSjakob.Nd write a daemon pid file 377ed310cbSjakob.Sh SYNOPSIS 38*86f9d4cdStedu.In util.h 397ed310cbSjakob.Ft int 407ed310cbSjakob.Fn pidfile "const char *basename" 417ed310cbSjakob.Sh DESCRIPTION 427ed310cbSjakob.Fn pidfile 437ed310cbSjakobwrites a file containing the process ID of the program to the 447ed310cbSjakob.Pa /var/run 4548a5a71aSmpechdirectory. 4648a5a71aSmpechThe file name has the form 477ed310cbSjakob.Pa /var/run/basename.pid . 487ed310cbSjakobIf the 497ed310cbSjakob.Ar basename 507ed310cbSjakobargument is NULL, 517ed310cbSjakob.Nm 527ed310cbSjakobwill determine the program name and use that instead. 537ed310cbSjakob.Pp 547ed310cbSjakobThe pid file can be used as a quick reference if 5548a5a71aSmpechthe process needs to be sent a signal. 5648a5a71aSmpechWhen the program exits, the pid file will be removed automatically, 5748a5a71aSmpechunless the program receives a fatal signal. 587ed310cbSjakob.Sh RETURN VALUES 597ed310cbSjakob.Fn pidfile 607ed310cbSjakobreturns 0 on success and -1 on failure. 617ed310cbSjakob.Sh SEE ALSO 627ed310cbSjakob.Xr atexit 3 637ed310cbSjakob.Sh HISTORY 647ed310cbSjakobThe 657ed310cbSjakob.Nm 667ed310cbSjakobfunction call appeared in 677ed310cbSjakob.Ox 3.0 . 686400e211Sjakob.Sh CAVEATS 696400e211SjakobIf 706400e211Sjakob.Fn pidfile 716400e211Sjakobis called multiple times with different 726400e211Sjakob.Ar basename , 736400e211Sjakobonly the last pidfile will be removed upon exit. 7483024207Smiod.Pp 7583024207Smiod.Fn pidfile 7683024207Smioduses 7783024207Smiod.Fn atexit 7883024207Smiodto ensure the pidfile is unlinked at program exit. 7983024207SmiodHowever, programs that use the 8083024207Smiod.Fn _exit 8183024207Smiodfunction (for example, in signal handlers) 8283024207Smiodwill not trigger this behaviour. 83