KVM_GETPROCS(3) BSD Programmer's Manual KVM_GETPROCS(3)
NAME
kvmgetprocs, kvmgetargv, kvmgetenvv - access user process state
SYNOPSIS
#include <kvm.h>
#include <sys/kinfo.h>
#include <sys/kinfoproc.h>
struct kinfoproc *
kvmgetprocs(kvmt *kd, int op, int arg, int *cnt)
char **
kvmgetargv(kvmt *kd, const struct kinfoproc *p, int nchr)
char **
kvmgetenvv(kvmt *kd, const struct kinfoproc *p, int nchr)
DESCRIPTION
kvmgetprocs() returns a (sub-)set of active processes in the kernel in-
dicated by kd. The op and arg arguments constitute a predicate which lim-
its the set of processes returned. The value of op describes the filter-
ing predicate as follows:
KINFOPROCALL all processes
KINFOPROCPID processes with process id arg
KINFOPROCPGRP processes with process group arg
KINFOPROCSESSION processes with session arg
KINFOPROCTTY processes with tty arg
KINFOPROCUID processes with effective user id arg
KINFOPROCRUID processes with real user id arg
The number of processes found is returned in the reference parameter cnt.
The processes are returned as a contiguous array of kinfo_proc struc-
tures. This memory is owned by kvm and is not guaranteed to be persis-
tent across subsequent kvm library calls. Data should be copied out if
it needs to be saved.
kvmgetargv() returns a null-terminated argument vector that corresponds
to the command line arguments passed to process indicated by p. Most
likely, these arguments correspond to the values passed to exec(3) on
process creation. This information is, however, deliberately under con-
trol of the process itself. Note that the original command name can be
found, unaltered, in the p_comm field of the process structure returned
by kvmgetprocs().
The nchr argument indicates the maximum number of characters, including
null bytes, to use in building the strings. If this amount is exceeded,
the string causing the overflow is truncated and the partial result is
returned. This is handy for programs like ps(1) and w(1) that print only
a one line summary of a command and should not copy out large amounts of
text only to ignore it. If nchr is zero, no limit is imposed and all ar-
gument strings are returned in their entirety.
The memory allocated to the argv pointers and string storage is owned by
the kvm library. Since subsequent kvm calls may clobber this storage,
data must be copied out if it needs to be saved.
The kvmgetenvv() function is similar to kvmgetargv() but returns the
vector of environment strings. This is data is also alterable by the
process.
RETURN VALUES
kvmgetprocs(), kvmgetargv(), and kvmgetenvv(), all return NULL on
failure.
BUGS
These routines do not belong in the kvm interface.
SEE ALSO
kvm(3), kvm_close(3), kvm_geterr(3), kvm_nlist(3), kvm_open(3),
kvm_openfiles(3), kvm_read(3), kvm_write(3)
BSDI BSD/386 March 26, 1993 2