Module Name: src Committed By: jruoho Date: Thu Mar 25 10:09:55 UTC 2010
Modified Files: src/share/man/man9: Makefile Added Files: src/share/man/man9: pfind.9 Log Message: Document p_find(), pfind(), pg_find(), and pgfind(). XXX: Needs a quick proofread. To generate a diff of this commit: cvs rdiff -u -r1.321 -r1.322 src/share/man/man9/Makefile cvs rdiff -u -r0 -r1.1 src/share/man/man9/pfind.9 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/share/man/man9/Makefile diff -u src/share/man/man9/Makefile:1.321 src/share/man/man9/Makefile:1.322 --- src/share/man/man9/Makefile:1.321 Mon Mar 22 10:32:48 2010 +++ src/share/man/man9/Makefile Thu Mar 25 10:09:54 2010 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.321 2010/03/22 10:32:48 jruoho Exp $ +# $NetBSD: Makefile,v 1.322 2010/03/25 10:09:54 jruoho Exp $ # Makefile for section 9 (kernel function and variable) manual pages. @@ -38,8 +38,8 @@ mstohz.9 mutex.9 m_tag.9 namecache.9 \ namei.9 opencrypto.9 optstr.9 \ panic.9 pci.9 pci_configure_bus.9 pci_intr.9 pckbport.9 \ - pcmcia.9 pcq.9 percpu.9 pfil.9 physio.9 pmap.9 pmatch.9 pmc.9 pmf.9 \ - pool.9 pool_cache.9 powerhook_establish.9 ppsratecheck.9 \ + pcmcia.9 pcq.9 percpu.9 pfil.9 pfind.9 physio.9 pmap.9 pmatch.9 \ + pmc.9 pmf.9 pool.9 pool_cache.9 powerhook_establish.9 ppsratecheck.9 \ preempt.9 putter.9 \ radio.9 ras.9 rasops.9 ratecheck.9 resettodr.9 rnd.9 roundup.9 \ rssadapt.9 rt_timer.9 rwlock.9 RUN_ONCE.9 \ @@ -522,6 +522,9 @@ pfil.9 pfil_head_unregister.9 \ pfil.9 pfil_head_get.9 \ pfil.9 pfil_run_hooks.9 +MLINKS+=pfind.9 p_find.9 \ + pfind.9 pg_find.9 \ + pfind.9 pgfind.9 MLINKS+=pmc.9 pmc_get_num_counters.9 \ pmc.9 pmc_get_counter_type.9 \ pmc.9 pmc_save_context.9 \ Added files: Index: src/share/man/man9/pfind.9 diff -u /dev/null src/share/man/man9/pfind.9:1.1 --- /dev/null Thu Mar 25 10:09:55 2010 +++ src/share/man/man9/pfind.9 Thu Mar 25 10:09:54 2010 @@ -0,0 +1,131 @@ +.\" $NetBSD: pfind.9,v 1.1 2010/03/25 10:09:54 jruoho 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 +are equivalent to +.Fn p_find +and +.Fn pg_find +with the +.Fa flags +argument specified as +.Dv PFIND_UNLOCK . +.Sh RETURN VALUES +Upon succesful 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