xref: /dragonfly/lib/libutil/pidfile.3 (revision 6bd457ed)
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 libutil.h
48.Ft int
49.Fn pidfile "const char *basename"
50.Sh DESCRIPTION
51.Fn pidfile
52writes a file containing the process ID of the program to the
53.Pa /var/run
54directory.
55The file name has the form
56.Pa /var/run/basename.pid .
57If the
58.Ar basename
59argument is NULL,
60.Nm
61will determine the program name and use that instead.
62.Pp
63The pid file can be used as a quick reference if
64the process needs to be sent a signal.
65When the program exits, the pid file will be removed automatically, unless
66the program receives a fatal signal.
67.Pp
68Note that only the first invocation of
69.Nm
70causes a pid file to be written; subsequent invocations have no effect
71unless a new
72.Ar basename
73is supplied.
74If called with a new
75.Ar basename ,
76.Fn pidfile
77will remove the old pid file and write the new one.
78.Sh RETURN VALUES
79.Fn pidfile
80returns 0 on success and -1 on failure.
81.Sh SEE ALSO
82.Xr atexit 3
83.Sh HISTORY
84The
85.Nm
86function call appeared in
87.Nx 1.5 .
88.Sh BUGS
89.Fn pidfile
90uses
91.Xr atexit 3
92to ensure the pidfile is unlinked at program exit.
93However, programs that use the
94.Xr _exit 2
95function (for example, in signal handlers)
96will not trigger this behaviour.
97