Main index | Section 3 | Options |
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <libprocstat.h>
The procstat_open_kvm() and procstat_open_sysctl() functions use the kvm(3) or sysctl(3) library routines, respectively, to access kernel state information used to retrieve processes and files states. The procstat_open_core() uses elf(3) routines to access statistics stored as a set of notes in a process core(5) file, written by the kernel at the moment of the process abnormal termination. The filename argument is the process core file name. The nlistf argument is the executable image of the kernel being examined. If this argument is NULL, the currently running kernel is assumed. The memf argument is the kernel memory device file. If this argument is NULL, then /dev/mem is assumed. See kvm_open(3) for more details. The functions dynamically allocate and return a procstat structure pointer used in the rest of the libprocstat library routines until the corresponding procstat_close() call that cleans up the resources allocated by the procstat_open_*() functions.
The procstat_getprocs() function gets a pointer to the procstat structure from one of the procstat_open_*() functions and returns a dynamically allocated (sub-)set of active processes in the kernel filled in to array of kinfo_proc structures. The what and arg arguments constitute a filtering predicate as described in the kvm_getprocs(3) function. The number of processes found is returned in the reference parameter cnt. The caller is responsible to free the allocated memory with a subsequent procstat_freeprocs() function call.
The procstat_getptlwpinfo() function gets a pointer to the procstat structure from the procstat_open_core() function and returns a dynamically allocated set of signals intercepted by a process in the process's core file. The number of processes found is returned in the reference parameter cnt. The caller is responsible to free the allocated memory with a subsequent procstat_freeptlwpinfo() function call.
The procstat_getargv() function gets a pointer to the procstat structure from one of the procstat_open_*() functions, a pointer to kinfo_proc structure from the array obtained from the procstat_getprocs() function, and returns a null-terminated argument vector that corresponds to the command line arguments passed to the process. 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 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 argument strings are returned. The values of the returned argument vector refer the strings stored in the procstat internal buffer. A subsequent call of the function with the same procstat argument will reuse the buffer. To free the allocated memory procstat_freeargv() function call can be used, or it will be released on procstat_close().
The procstat_getenvv() function is similar to procstat_getargv() but returns the vector of environment strings. The caller may free the allocated memory with a subsequent procstat_freeenvv() function call.
The procstat_getauxv() function gets a pointer to the procstat structure, a pointer to kinfo_proc structure, and returns the auxiliary vector as a dynamically allocated array of Elf_Auxinfo elements. The caller is responsible to free the allocated memory with a subsequent procstat_freeauxv() function call.
The procstat_getfiles() function gets a pointer to the procstat structure initialized with one of the procstat_open_*() functions, a pointer to kinfo_proc structure from the array obtained from the procstat_getprocs() function, and returns a dynamically allocated linked list of filled in filestat_list structures using the STAILQ macros defined in queue(3). The caller is responsible to free the allocated memory with a subsequent procstat_freefiles() function call.
The procstat_getgroups() function gets a pointer to the procstat structure, a pointer to kinfo_proc structure, and returns the process groups as a dynamically allocated array of gid_t elements. The caller is responsible to free the allocated memory with a subsequent procstat_freegroups() function call.
The procstat_getkstack() function gets a pointer to the procstat structure initialized with one of the procstat_open_*() functions, a pointer to kinfo_proc structure, and returns kernel stacks of the process as a dynamically allocated array of kinfo_kstack structures. The caller is responsible to free the allocated memory with a subsequent procstat_freekstack() function call.
The procstat_getosrel() function gets a pointer to the procstat structure, a pointer to kinfo_proc structure, and returns osrel date in the 3rd reference parameter.
The procstat_getpathname() function gets a pointer to the procstat structure, a pointer to kinfo_proc structure, and copies the path of the process executable to pathname buffer, limiting to maxlen characters.
The procstat_getrlimit() function gets a pointer to the procstat structure, a pointer to kinfo_proc structure, resource index which, and returns the actual resource limit in the 4th reference parameter.
The procstat_getumask() function gets a pointer to the procstat structure, a pointer to kinfo_proc structure, and returns the process umask in the 3rd reference parameter.
The procstat_getvmmap() function gets a pointer to the procstat structure initialized with one of the procstat_open_*() functions, a pointer to kinfo_proc structure, and returns VM layout of the process as a dynamically allocated array of kinfo_vmentry structures. The caller is responsible to free the allocated memory with a subsequent procstat_freevmmap() function call.
The procstat_getadvlock() function returns a dynamically allocated list of struct advlock structures, providing a snapshot of the currently acquired advisory locks in the system. Both locally acquired POSIX ( fcntl(2)) and BSD-style ( flock(2)) locks are reported, as well as locks established by remote file system protocols. For each lock, unique identifiers for the locked file and its mount point are guaranteed to be provided. If a path for the locked file can be reconstructed, it is provided as well. The returned list must be freed with the procstat_freeadvlock() function.
The procstat_get_pipe_info(), procstat_get_pts_info(), procstat_get_sem_info(), procstat_get_shm_info(), procstat_get_socket_info() and procstat_get_vnode_info() functions are used to retrieve information about pipes, pseudo-terminals, semaphores, shared memory objects, sockets, and vnodes, respectively. Each of them have a similar interface API. The procstat argument is a pointer obtained from one of procstat_open_*() functions. The filestatfst argument is an element of STAILQ linked list as obtained from the procstat_getfiles() function. The filestat structure contains a fs_type field that specifies a file type and a corresponding function to be called among the procstat_get_*_info function family. The actual object is returned in the 3rd reference parameter. The errbuf argument indicates an actual error message in case of failure.
PS_FST_TYPE_FIFO | |
procstat_get_vnode_info | |
PS_FST_TYPE_VNODE | |
procstat_get_vnode_info | |
PS_FST_TYPE_SOCKET | |
procstat_get_socket_info | |
PS_FST_TYPE_PIPE | |
procstat_get_pipe_info | |
PS_FST_TYPE_PTS | |
procstat_get_pts_info | |
PS_FST_TYPE_SEM | |
procstat_get_sem_info | |
PS_FST_TYPE_SHM | |
procstat_get_shm_info | |
This manual page was written by Sergey Kandaurov <Mt pluknet@FreeBSD.org>.
LIBPROCSTAT (3) | April 3, 2022 |
Main index | Section 3 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | The most horrifying thing about Unix is that, no matter how many times you hit yourself over the head with it, you never quite manage to lose consciousness. It just goes on and on. | ” |
— Patrick Sobalvarro |