NetBSD/share/man/man9/pfind.9

132 lines
3.3 KiB
Groff

.\" $NetBSD: pfind.9,v 1.2 2010/03/26 19:43:04 wiz Exp $
.\"
.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Jukka Ruohonen.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd March 25, 2010
.Dt PFIND 9
.Os
.Sh NAME
.Nm pfind
.Nd find process or process group by a number
.Sh SYNOPSIS
.In sys/proc.h
.Ft struct proc *
.Fn p_find "pid_t pid" "uint flags"
.Ft struct proc *
.Fn pfind "pid_t pid"
.Ft struct pgrp *
.Fn pg_find "pid_t pgid" "uint flags"
.Ft struct pgrp *
.Fn pgfind "pid_t pgid"
.Pp
.Va extern kmutex_t *proc_lock;
.Sh DESCRIPTION
The
.Fn p_find
and
.Fn pg_find
functions retrieve process and process group structures from process
.Tn ID
.Fa pid
and process group
.Tn ID
.Fa pgid .
The following
.Fa flags
are defined:
.Bl -tag -width "PFIND_UNLOCK_FAIL" -offset indent
.It Dv PFIND_ZOMBIE
The lookup includes also the list of
.Dq zombie
processes.
.It Dv PFIND_LOCKED
The list of processes is locked prior to the call by holding a
.Xr mutex 9
on
.Va proc_lock .
If
.Dv PFIND_LOCKED
is not specified, the implementation tries to acquire the mutex.
.It Dv PFIND_UNLOCK_FAIL
The list of processes is unlocked upon failure.
.It Dv PFIND_UNLOCK_OK
The list of processes is unlocked upon success.
.It Dv PFIND_UNLOCK
The implementation releases the
.Xr mutex 9
on
.Va proc_lock
both upon failure and success.
.El
.Pp
The
.Fn pfind
and
.Fn pgfind
functions are equivalent to
.Fn p_find
and
.Fn pg_find
with the
.Fa flags
argument specified as
.Dv PFIND_UNLOCK .
.Sh RETURN VALUES
Upon successful completion, the described functions return a pointer to either
.Em struct proc
or
.Em struct pgrp .
Otherwise, if the requested
.Tn ID
was not found,
.Dv NULL
is returned.
.Sh EXAMPLES
The following example demonstrates the use of
.Fn p_find :
.Bd -literal -offset indent
struct proc *p;
pid_t pid;
\&...
mutex_enter(proc_lock);
p = p_find(pid, PFIND_LOCKED | PFIND_UNLOCK_OK);
if (p == NULL) {
mutex_exit(proc_lock);
return ESRCH;
}
\&...
.Ed
.Sh SEE ALSO
.Xr curproc 9 ,
.Xr mutex 9