xref: /src/share/man/man9/pfind.9 (revision 2ace05b65a2c912888aeec921fc6f990a5c36909)
1.\" Copyright (c) 2001 Evan Sarmiento.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd November 3, 2025
26.Dt PFIND 9
27.Os
28.Sh NAME
29.Nm pfind ,
30.Nm pfind_any ,
31.Nm pfind_any_locked
32.Nd locate a process by number
33.Sh SYNOPSIS
34.In sys/param.h
35.In sys/proc.h
36.Ft "struct proc *"
37.Fn pfind "pid_t pid"
38.Ft "struct proc *"
39.Fn pfind_any "pid_t pid"
40.Ft "struct proc *"
41.Fn pfind_any_locked "pid_t pid"
42.Sh DESCRIPTION
43The
44.Fn pfind
45function walks the list of processes in the system, looking for the one with a
46process ID of
47.Fa pid .
48If the process exists, and is not in the zombie state, a pointer to the process
49structure will be returned.
50.Pp
51.Fn pfind_any
52takes a
53.Fa pid
54as its argument.
55.Fn pfind_any
56searches the
57.Va allproc
58list and returns the first process with a matching PID, whose state may be
59.Dv PRS_ZOMBIE .
60.Pp
61.Fn pfind_any_locked
62is similar to
63.Fn pfind_any ,
64but it does not lock the process hash bucket for the given
65.Vt pid .
66Instead, it asserts the corresponding process hash bucket is already locked.
67.Pp
68All three functions
69.Fn pfind ,
70.Fn pfind_any ,
71and
72.Fn pfind_any_locked
73lock the
74.Vt proc
75structure before returning.
76.Sh RETURN VALUES
77.Fn pfind ,
78.Fn pfind_any ,
79and
80.Fn pfind_any_locked
81return pointer to a
82.Vt proc
83structure on success or
84.Dv NULL
85on failure.
86.Sh SEE ALSO
87.Xr pget 9 ,
88.Xr pgfind 9
89.Sh AUTHORS
90This manual page was written by
91.An Evan Sarmiento Aq Mt kaworu@sektor7.ath.cx .
92