1.\" Copyright (c) 1992, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software developed by the Computer Systems 5.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract 6.\" BG 91-66 and contributed to Berkeley. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.Dd November 22, 2011 33.Dt KVM_GETPROCS 3 34.Os 35.Sh NAME 36.Nm kvm_getprocs , 37.Nm kvm_getargv , 38.Nm kvm_getenvv 39.Nd access user process state 40.Sh LIBRARY 41.Lb libkvm 42.Sh SYNOPSIS 43.In kvm.h 44.In sys/param.h 45.In sys/sysctl.h 46.In sys/user.h 47.Ft struct kinfo_proc * 48.Fn kvm_getprocs "kvm_t *kd" "int op" "int arg" "int *cnt" 49.Ft char ** 50.Fn kvm_getargv "kvm_t *kd" "const struct kinfo_proc *p" "int nchr" 51.Ft char ** 52.Fn kvm_getenvv "kvm_t *kd" "const struct kinfo_proc *p" "int nchr" 53.Sh DESCRIPTION 54The 55.Fn kvm_getprocs 56function returns a (sub-)set of active processes in the kernel indicated by 57.Fa kd . 58The 59.Fa op 60and 61.Fa arg 62arguments constitute a predicate which limits the set of processes 63returned. 64The value of 65.Fa op 66describes the filtering predicate as follows: 67.Pp 68.Bl -tag -width 20n -offset indent -compact 69.It Dv KERN_PROC_ALL 70all processes and kernel visible threads 71.It Dv KERN_PROC_PROC 72all processes, without threads 73.It Dv KERN_PROC_PID 74processes with process ID 75.Fa arg 76.It Dv KERN_PROC_PGRP 77processes with process group 78.Fa arg 79.It Dv KERN_PROC_SESSION 80processes with session 81.Fa arg 82.It Dv KERN_PROC_TTY 83processes with TTY 84.Fa arg 85.It Dv KERN_PROC_UID 86processes with effective user ID 87.Fa arg 88.It Dv KERN_PROC_RUID 89processes with real user ID 90.Fa arg 91.It Dv KERN_PROC_INC_THREAD 92modifier to return all kernel visible threads when filtering 93by process ID, process group, TTY, user ID, and real user ID 94.El 95.Pp 96The number of processes found is returned in the reference parameter 97.Fa cnt . 98The processes are returned as a contiguous array of kinfo_proc structures. 99This memory is locally allocated, and subsequent calls to 100.Fn kvm_getprocs 101and 102.Fn kvm_close 103will overwrite this storage. 104.Pp 105The 106.Fn kvm_getargv 107function returns a null-terminated argument vector that corresponds to the 108command line arguments passed to process indicated by 109.Fa p . 110Most likely, these arguments correspond to the values passed to 111.Xr exec 3 112on process creation. 113This information is, however, 114deliberately under control of the process itself. 115Note that the original command name can be found, unaltered, 116in the p_comm field of the process structure returned by 117.Fn kvm_getprocs . 118.Pp 119The 120.Fa nchr 121argument indicates the maximum number of characters, including null bytes, 122to use in building the strings. 123If this amount is exceeded, the string 124causing the overflow is truncated and the partial result is returned. 125This is handy for programs like 126.Xr ps 1 127and 128.Xr w 1 129that print only a one line summary of a command and should not copy 130out large amounts of text only to ignore it. 131If 132.Fa nchr 133is zero, no limit is imposed and all argument strings are returned in 134their entirety. 135.Pp 136The memory allocated to the argv pointers and string storage 137is owned by the kvm library. 138Subsequent 139.Fn kvm_getprocs 140and 141.Xr kvm_close 3 142calls will clobber this storage. 143.Pp 144The 145.Fn kvm_getenvv 146function is similar to 147.Fn kvm_getargv 148but returns the vector of environment strings. 149This data is 150also alterable by the process. 151.Sh RETURN VALUES 152The 153.Fn kvm_getprocs , 154.Fn kvm_getargv , 155and 156.Fn kvm_getenvv 157functions return 158.Dv NULL 159on failure. 160.Sh SEE ALSO 161.Xr kvm 3 , 162.Xr kvm_close 3 , 163.Xr kvm_geterr 3 , 164.Xr kvm_nlist 3 , 165.Xr kvm_open 3 , 166.Xr kvm_openfiles 3 , 167.Xr kvm_read 3 , 168.Xr kvm_write 3 169.Sh BUGS 170These routines do not belong in the kvm interface. 171