158f0484fSRodney W. Grimes.\" Copyright (c) 1992, 1993 258f0484fSRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 358f0484fSRodney W. Grimes.\" 458f0484fSRodney W. Grimes.\" This code is derived from software developed by the Computer Systems 558f0484fSRodney W. Grimes.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract 658f0484fSRodney W. Grimes.\" BG 91-66 and contributed to Berkeley. 758f0484fSRodney W. Grimes.\" 858f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 958f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions 1058f0484fSRodney W. Grimes.\" are met: 1158f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 1258f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 1358f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 1458f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 1558f0484fSRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 1658f0484fSRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software 1758f0484fSRodney W. Grimes.\" must display the following acknowledgement: 1858f0484fSRodney W. Grimes.\" This product includes software developed by the University of 1958f0484fSRodney W. Grimes.\" California, Berkeley and its contributors. 2058f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors 2158f0484fSRodney W. Grimes.\" may be used to endorse or promote products derived from this software 2258f0484fSRodney W. Grimes.\" without specific prior written permission. 2358f0484fSRodney W. Grimes.\" 2458f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2558f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2658f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2758f0484fSRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2858f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2958f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3058f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3158f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3258f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3358f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3458f0484fSRodney W. Grimes.\" SUCH DAMAGE. 3558f0484fSRodney W. Grimes.\" 3658f0484fSRodney W. Grimes.\" @(#)kvm_getprocs.3 8.1 (Berkeley) 6/4/93 377f3dea24SPeter Wemm.\" $FreeBSD$ 3858f0484fSRodney W. Grimes.\" 3938e97393STim J. Robbins.Dd September 27, 2003 4058f0484fSRodney W. Grimes.Dt KVM_GETPROCS 3 4158f0484fSRodney W. Grimes.Os 4258f0484fSRodney W. Grimes.Sh NAME 4358f0484fSRodney W. Grimes.Nm kvm_getprocs , 4458f0484fSRodney W. Grimes.Nm kvm_getargv , 4558f0484fSRodney W. Grimes.Nm kvm_getenvv 4658f0484fSRodney W. Grimes.Nd access user process state 477f5e8c84SAlexey Zelkin.Sh LIBRARY 487f5e8c84SAlexey Zelkin.Lb libkvm 4958f0484fSRodney W. Grimes.Sh SYNOPSIS 5032eef9aeSRuslan Ermilov.In kvm.h 5132eef9aeSRuslan Ermilov.In sys/param.h 5232eef9aeSRuslan Ermilov.In sys/sysctl.h 53225823c5STom Rhodes.In sys/user.h 5458f0484fSRodney W. Grimes.\" .Fa kvm_t *kd 5558f0484fSRodney W. Grimes.Ft struct kinfo_proc * 5658f0484fSRodney W. Grimes.Fn kvm_getprocs "kvm_t *kd" "int op" "int arg" "int *cnt" 5758f0484fSRodney W. Grimes.Ft char ** 5858f0484fSRodney W. Grimes.Fn kvm_getargv "kvm_t *kd" "const struct kinfo_proc *p" "int nchr" 5958f0484fSRodney W. Grimes.Ft char ** 6058f0484fSRodney W. Grimes.Fn kvm_getenvv "kvm_t *kd" "const struct kinfo_proc *p" "int nchr" 6158f0484fSRodney W. Grimes.Sh DESCRIPTION 624cacb618SPhilippe CharnierThe 6358f0484fSRodney W. Grimes.Fn kvm_getprocs 644cacb618SPhilippe Charnierfunction returns a (sub-)set of active processes in the kernel indicated by 6558f0484fSRodney W. Grimes.Fa kd . 6658f0484fSRodney W. GrimesThe 6758f0484fSRodney W. Grimes.Fa op 6858f0484fSRodney W. Grimesand 6958f0484fSRodney W. Grimes.Fa arg 7058f0484fSRodney W. Grimesarguments constitute a predicate which limits the set of processes 711a0a9345SRuslan Ermilovreturned. 721a0a9345SRuslan ErmilovThe value of 7358f0484fSRodney W. Grimes.Fa op 7458f0484fSRodney W. Grimesdescribes the filtering predicate as follows: 7558f0484fSRodney W. Grimes.Pp 7658f0484fSRodney W. Grimes.Bl -tag -width 20n -offset indent -compact 77862b46f6SRuslan Ermilov.It Dv KERN_PROC_ALL 7838e97393STim J. Robbinsall processes and kernel visible threads 79862b46f6SRuslan Ermilov.It Dv KERN_PROC_PROC 8038e97393STim J. Robbinsall processes, without threads 81862b46f6SRuslan Ermilov.It Dv KERN_PROC_PID 82862b46f6SRuslan Ermilovprocesses with process ID 8358f0484fSRodney W. Grimes.Fa arg 84862b46f6SRuslan Ermilov.It Dv KERN_PROC_PGRP 8558f0484fSRodney W. Grimesprocesses with process group 8658f0484fSRodney W. Grimes.Fa arg 87862b46f6SRuslan Ermilov.It Dv KERN_PROC_SESSION 8858f0484fSRodney W. Grimesprocesses with session 8958f0484fSRodney W. Grimes.Fa arg 90862b46f6SRuslan Ermilov.It Dv KERN_PROC_TTY 91862b46f6SRuslan Ermilovprocesses with TTY 9258f0484fSRodney W. Grimes.Fa arg 93862b46f6SRuslan Ermilov.It Dv KERN_PROC_UID 94862b46f6SRuslan Ermilovprocesses with effective user ID 9558f0484fSRodney W. Grimes.Fa arg 96862b46f6SRuslan Ermilov.It Dv KERN_PROC_RUID 97862b46f6SRuslan Ermilovprocesses with real user ID 9858f0484fSRodney W. Grimes.Fa arg 99862b46f6SRuslan Ermilov.It Dv KERN_PROC_INC_THREAD 100f3e170bbSDaniel Eischenmodifier to return all kernel visible threads when filtering 101862b46f6SRuslan Ermilovby process ID, process group, TTY, user ID, and real user ID 10258f0484fSRodney W. Grimes.El 10358f0484fSRodney W. Grimes.Pp 10458f0484fSRodney W. GrimesThe number of processes found is returned in the reference parameter 10558f0484fSRodney W. Grimes.Fa cnt . 10658f0484fSRodney W. GrimesThe processes are returned as a contiguous array of kinfo_proc structures. 10758f0484fSRodney W. GrimesThis memory is locally allocated, and subsequent calls to 10858f0484fSRodney W. Grimes.Fn kvm_getprocs 10958f0484fSRodney W. Grimesand 11058f0484fSRodney W. Grimes.Fn kvm_close 11158f0484fSRodney W. Grimeswill overwrite this storage. 11258f0484fSRodney W. Grimes.Pp 1134cacb618SPhilippe CharnierThe 11458f0484fSRodney W. Grimes.Fn kvm_getargv 1154cacb618SPhilippe Charnierfunction returns a null-terminated argument vector that corresponds to the 11658f0484fSRodney W. Grimescommand line arguments passed to process indicated by 11758f0484fSRodney W. Grimes.Fa p . 11858f0484fSRodney W. GrimesMost likely, these arguments correspond to the values passed to 11958f0484fSRodney W. Grimes.Xr exec 3 1201a0a9345SRuslan Ermilovon process creation. 1211a0a9345SRuslan ErmilovThis information is, however, 12258f0484fSRodney W. Grimesdeliberately under control of the process itself. 12358f0484fSRodney W. GrimesNote that the original command name can be found, unaltered, 12458f0484fSRodney W. Grimesin the p_comm field of the process structure returned by 12558f0484fSRodney W. Grimes.Fn kvm_getprocs . 12658f0484fSRodney W. Grimes.Pp 12758f0484fSRodney W. GrimesThe 12858f0484fSRodney W. Grimes.Fa nchr 12958f0484fSRodney W. Grimesargument indicates the maximum number of characters, including null bytes, 1301a0a9345SRuslan Ermilovto use in building the strings. 1311a0a9345SRuslan ErmilovIf this amount is exceeded, the string 13258f0484fSRodney W. Grimescausing the overflow is truncated and the partial result is returned. 13358f0484fSRodney W. GrimesThis is handy for programs like 13458f0484fSRodney W. Grimes.Xr ps 1 13558f0484fSRodney W. Grimesand 13658f0484fSRodney W. Grimes.Xr w 1 13758f0484fSRodney W. Grimesthat print only a one line summary of a command and should not copy 13858f0484fSRodney W. Grimesout large amounts of text only to ignore it. 13958f0484fSRodney W. GrimesIf 14058f0484fSRodney W. Grimes.Fa nchr 14158f0484fSRodney W. Grimesis zero, no limit is imposed and all argument strings are returned in 14258f0484fSRodney W. Grimestheir entirety. 14358f0484fSRodney W. Grimes.Pp 14458f0484fSRodney W. GrimesThe memory allocated to the argv pointers and string storage 1451a0a9345SRuslan Ermilovis owned by the kvm library. 1461a0a9345SRuslan ErmilovSubsequent 14758f0484fSRodney W. Grimes.Fn kvm_getprocs 14858f0484fSRodney W. Grimesand 14958f0484fSRodney W. Grimes.Xr kvm_close 3 15058f0484fSRodney W. Grimescalls will clobber this storage. 15158f0484fSRodney W. Grimes.Pp 15258f0484fSRodney W. GrimesThe 15358f0484fSRodney W. Grimes.Fn kvm_getenvv 15458f0484fSRodney W. Grimesfunction is similar to 15558f0484fSRodney W. Grimes.Fn kvm_getargv 1561a0a9345SRuslan Ermilovbut returns the vector of environment strings. 1571a0a9345SRuslan ErmilovThis data is 15858f0484fSRodney W. Grimesalso alterable by the process. 15958f0484fSRodney W. Grimes.Sh RETURN VALUES 1604cacb618SPhilippe CharnierThe 16158f0484fSRodney W. Grimes.Fn kvm_getprocs , 16258f0484fSRodney W. Grimes.Fn kvm_getargv , 16358f0484fSRodney W. Grimesand 1644cacb618SPhilippe Charnier.Fn kvm_getenvv 1654cacb618SPhilippe Charnierfunctions return 16658f0484fSRodney W. Grimes.Dv NULL 16758f0484fSRodney W. Grimeson failure. 16858f0484fSRodney W. Grimes.Sh SEE ALSO 16958f0484fSRodney W. Grimes.Xr kvm 3 , 17058f0484fSRodney W. Grimes.Xr kvm_close 3 , 17158f0484fSRodney W. Grimes.Xr kvm_geterr 3 , 17258f0484fSRodney W. Grimes.Xr kvm_nlist 3 , 17358f0484fSRodney W. Grimes.Xr kvm_open 3 , 17458f0484fSRodney W. Grimes.Xr kvm_openfiles 3 , 17558f0484fSRodney W. Grimes.Xr kvm_read 3 , 17658f0484fSRodney W. Grimes.Xr kvm_write 3 17724a0682cSRuslan Ermilov.Sh BUGS 17824a0682cSRuslan ErmilovThese routines do not belong in the kvm interface. 17924a0682cSRuslan Ermilov.Pp 18024a0682cSRuslan ErmilovIn order for 18124a0682cSRuslan Ermilov.Xr kvm_getenvv 3 18224a0682cSRuslan Ermilovto function correctly, 18324a0682cSRuslan Ermilov.Xr procfs 5 18424a0682cSRuslan Ermilovmust be mounted on 18524a0682cSRuslan Ermilov.Pa /proc . 186