OpenBSD manual page server

Manual Page Search Parameters

KVM_GETFILES(3) Library Functions Manual KVM_GETFILES(3)

kvm_getfilessurvey open files

#include <kvm.h>
#include <sys/types.h>
#include <sys/sysctl.h>

struct kinfo_file *
kvm_getfiles(kvm_t *kd, int op, int arg, size_t elemsize, int *cnt);

() returns a (sub-)set of the open files in the kernel indicated by kd. The op and arg arguments constitute a predicate which limits the set of files returned. The value of op describes the filtering predicate as follows:

all open files with type arg (0 for all files)
files opened by process ID arg (-1 for all processes)
files opened by processes with effective user ID arg (-1 for all users)

Files associated with a process will include information about the process that has the file open.

For KERN_FILE_BYFILE the recognized file types are defined in <sys/file.h>:

files and devices
sockets, regardless of domain
pipes and FIFOs
kqueues

Only the first elemsize bytes of each array entry are returned. If the size of the kinfo_file structure increases in size in a future release of OpenBSD, the kernel will only return the requested amount of data for each array entry and programs that use () will continue to function without the need for recompilation.

The files are returned as a contiguous array of kinfo_file structures. The number of structures found is returned in the reference parameter cnt. This memory is owned by kvm and will be overwritten by subsequent calls to kvm_getfiles() and destroyed by kvm_close(). Data should be copied out if it needs to be saved.

kvm_getfiles() will return NULL on failure.

kvm_getfiles() will fail if:

[]
Could not allocate enough memory for internal buffer.
[]
The op argument has KERN_FILE_BYPID value and the process specified by arg was not found.

kvm(3), kvm_geterr(3), kvm_nlist(3), kvm_open(3), kvm_read(3)

This routine does not belong in the kvm interface.

May 4, 2016 OpenBSD-7.5