1c66ca772SSergey Kandaurov.\" Copyright (c) 2011 Sergey Kandaurov <[email protected]> 2c66ca772SSergey Kandaurov.\" All rights reserved. 3c66ca772SSergey Kandaurov.\" 4c66ca772SSergey Kandaurov.\" Redistribution and use in source and binary forms, with or without 5c66ca772SSergey Kandaurov.\" modification, are permitted provided that the following conditions 6c66ca772SSergey Kandaurov.\" are met: 7c66ca772SSergey Kandaurov.\" 1. Redistributions of source code must retain the above copyright 8c66ca772SSergey Kandaurov.\" notice, this list of conditions and the following disclaimer. 9c66ca772SSergey Kandaurov.\" 2. Redistributions in binary form must reproduce the above copyright 10c66ca772SSergey Kandaurov.\" notice, this list of conditions and the following disclaimer in the 11c66ca772SSergey Kandaurov.\" documentation and/or other materials provided with the distribution. 12c66ca772SSergey Kandaurov.\" 13c66ca772SSergey Kandaurov.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14c66ca772SSergey Kandaurov.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15c66ca772SSergey Kandaurov.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16c66ca772SSergey Kandaurov.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17c66ca772SSergey Kandaurov.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18c66ca772SSergey Kandaurov.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19c66ca772SSergey Kandaurov.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20c66ca772SSergey Kandaurov.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21c66ca772SSergey Kandaurov.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22c66ca772SSergey Kandaurov.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23c66ca772SSergey Kandaurov.\" SUCH DAMAGE. 24c66ca772SSergey Kandaurov.\" 25*50d3c725SKonstantin Belousov.Dd April 3, 2022 26c66ca772SSergey Kandaurov.Dt LIBPROCSTAT 3 27c66ca772SSergey Kandaurov.Os 28c66ca772SSergey Kandaurov.Sh NAME 29c66ca772SSergey Kandaurov.Nm procstat_close , 30*50d3c725SKonstantin Belousov.Nm procstat_freeadvlock , 314482b5e3SMikolaj Golub.Nm procstat_freeargv , 322ff020d3SMikolaj Golub.Nm procstat_freeauxv , 334482b5e3SMikolaj Golub.Nm procstat_freeenvv , 34c66ca772SSergey Kandaurov.Nm procstat_freefiles , 357f1d14e6SMikolaj Golub.Nm procstat_freegroups , 3689358231SMikolaj Golub.Nm procstat_freekstack , 37c66ca772SSergey Kandaurov.Nm procstat_freeprocs , 38c45beed8SEnji Cooper.Nm procstat_freeptlwpinfo , 3939680c7bSMikolaj Golub.Nm procstat_freevmmap , 40c66ca772SSergey Kandaurov.Nm procstat_get_pipe_info , 41c66ca772SSergey Kandaurov.Nm procstat_get_pts_info , 42958aa575SJohn Baldwin.Nm procstat_get_sem_info , 43e506e182SJohn Baldwin.Nm procstat_get_shm_info , 44c66ca772SSergey Kandaurov.Nm procstat_get_socket_info , 4504017fc7SAllan Jude.Nm procstat_get_vnode_info , 46*50d3c725SKonstantin Belousov.Nm procstat_getadvlock , 4704017fc7SAllan Jude.Nm procstat_getargv , 4804017fc7SAllan Jude.Nm procstat_getauxv , 4904017fc7SAllan Jude.Nm procstat_getenvv , 5004017fc7SAllan Jude.Nm procstat_getfiles , 5104017fc7SAllan Jude.Nm procstat_getgroups , 5204017fc7SAllan Jude.Nm procstat_getkstack , 5304017fc7SAllan Jude.Nm procstat_getosrel , 5404017fc7SAllan Jude.Nm procstat_getpathname , 5504017fc7SAllan Jude.Nm procstat_getprocs , 56c45beed8SEnji Cooper.Nm procstat_getptlwpinfo , 5704017fc7SAllan Jude.Nm procstat_getrlimit , 5804017fc7SAllan Jude.Nm procstat_getumask , 5904017fc7SAllan Jude.Nm procstat_getvmmap , 6004017fc7SAllan Jude.Nm procstat_open_core , 6104017fc7SAllan Jude.Nm procstat_open_kvm , 6204017fc7SAllan Jude.Nm procstat_open_sysctl 63c66ca772SSergey Kandaurov.Nd library interface for file and process information retrieval 64c66ca772SSergey Kandaurov.Sh LIBRARY 65c66ca772SSergey Kandaurov.Lb libprocstat 66c66ca772SSergey Kandaurov.Sh SYNOPSIS 67c66ca772SSergey Kandaurov.In sys/param.h 68c66ca772SSergey Kandaurov.In sys/queue.h 69e504201eSEnji Cooper.In sys/socket.h 70c66ca772SSergey Kandaurov.In libprocstat.h 71c66ca772SSergey Kandaurov.Ft void 72c66ca772SSergey Kandaurov.Fn procstat_close "struct procstat *procstat" 73c66ca772SSergey Kandaurov.Ft void 74*50d3c725SKonstantin Belousov.Fn procstat_freeadvlock "struct procstat *procstat" "struct advlock_list *list" 75*50d3c725SKonstantin Belousov.Ft void 764482b5e3SMikolaj Golub.Fo procstat_freeargv 774482b5e3SMikolaj Golub.Fa "struct procstat *procstat" 784482b5e3SMikolaj Golub.Fc 794482b5e3SMikolaj Golub.Ft void 802ff020d3SMikolaj Golub.Fo procstat_freeauxv 812ff020d3SMikolaj Golub.Fa "struct procstat *procstat" 822ff020d3SMikolaj Golub.Fa "Elf_Auxinfo *auxv" 832ff020d3SMikolaj Golub.Fc 842ff020d3SMikolaj Golub.Ft void 854482b5e3SMikolaj Golub.Fo procstat_freeenvv 864482b5e3SMikolaj Golub.Fa "struct procstat *procstat" 874482b5e3SMikolaj Golub.Fc 884482b5e3SMikolaj Golub.Ft void 89c66ca772SSergey Kandaurov.Fo procstat_freefiles 90c66ca772SSergey Kandaurov.Fa "struct procstat *procstat" 91c66ca772SSergey Kandaurov.Fa "struct filestat_list *head" 92c66ca772SSergey Kandaurov.Fc 93c66ca772SSergey Kandaurov.Ft void 947f1d14e6SMikolaj Golub.Fo procstat_freegroups 957f1d14e6SMikolaj Golub.Fa "struct procstat *procstat" 967f1d14e6SMikolaj Golub.Fa "gid_t *groups" 977f1d14e6SMikolaj Golub.Fc 987f1d14e6SMikolaj Golub.Ft void 9989358231SMikolaj Golub.Fo procstat_freekstack 10089358231SMikolaj Golub.Fa "struct procstat *procstat" 10189358231SMikolaj Golub.Fa "struct kinfo_kstack *kkstp" 10289358231SMikolaj Golub.Fc 10389358231SMikolaj Golub.Ft void 104c66ca772SSergey Kandaurov.Fn procstat_freeprocs "struct procstat *procstat" "struct kinfo_proc *p" 10539680c7bSMikolaj Golub.Ft void 10639680c7bSMikolaj Golub.Fo procstat_freevmmap 10739680c7bSMikolaj Golub.Fa "struct procstat *procstat" 10839680c7bSMikolaj Golub.Fa "struct kinfo_vmentry *vmmap" 10939680c7bSMikolaj Golub.Fc 110c45beed8SEnji Cooper.Ft void 111c45beed8SEnji Cooper.Fo procstat_freeptlwpinfo 112c45beed8SEnji Cooper.Fa "struct procstat *procstat" 113c45beed8SEnji Cooper.Fa "struct ptrace_lwpinfo *pl" 114c45beed8SEnji Cooper.Fc 115c66ca772SSergey Kandaurov.Ft int 116c66ca772SSergey Kandaurov.Fo procstat_get_pipe_info 117c66ca772SSergey Kandaurov.Fa "struct procstat *procstat" 118c66ca772SSergey Kandaurov.Fa "struct filestat *fst" 119c66ca772SSergey Kandaurov.Fa "struct pipestat *pipe" 120c66ca772SSergey Kandaurov.Fa "char *errbuf" 121c66ca772SSergey Kandaurov.Fc 122c66ca772SSergey Kandaurov.Ft int 123c66ca772SSergey Kandaurov.Fo procstat_get_pts_info 124c66ca772SSergey Kandaurov.Fa "struct procstat *procstat" 125c66ca772SSergey Kandaurov.Fa "struct filestat *fst" 126c66ca772SSergey Kandaurov.Fa "struct ptsstat *pts" 127c66ca772SSergey Kandaurov.Fa "char *errbuf" 128c66ca772SSergey Kandaurov.Fc 129c66ca772SSergey Kandaurov.Ft int 130958aa575SJohn Baldwin.Fo procstat_get_sem_info 131958aa575SJohn Baldwin.Fa "struct procstat *procstat" 132958aa575SJohn Baldwin.Fa "struct filestat *fst" 133958aa575SJohn Baldwin.Fa "struct semstat *sem" 134958aa575SJohn Baldwin.Fa "char *errbuf" 135958aa575SJohn Baldwin.Fc 136958aa575SJohn Baldwin.Ft int 137e506e182SJohn Baldwin.Fo procstat_get_shm_info 138e506e182SJohn Baldwin.Fa "struct procstat *procstat" 139e506e182SJohn Baldwin.Fa "struct filestat *fst" 140e506e182SJohn Baldwin.Fa "struct shmstat *shm" 141e506e182SJohn Baldwin.Fa "char *errbuf" 142e506e182SJohn Baldwin.Fc 143e506e182SJohn Baldwin.Ft int 144c66ca772SSergey Kandaurov.Fo procstat_get_socket_info 145c66ca772SSergey Kandaurov.Fa "struct procstat *procstat" 146c66ca772SSergey Kandaurov.Fa "struct filestat *fst" 147c66ca772SSergey Kandaurov.Fa "struct sockstat *sock" 148c66ca772SSergey Kandaurov.Fa "char *errbuf" 149c66ca772SSergey Kandaurov.Fc 150c66ca772SSergey Kandaurov.Ft int 151c66ca772SSergey Kandaurov.Fo procstat_get_vnode_info 152c66ca772SSergey Kandaurov.Fa "struct procstat *procstat" 153c66ca772SSergey Kandaurov.Fa "struct filestat *fst" 154c66ca772SSergey Kandaurov.Fa "struct vnstat *vn" 155c66ca772SSergey Kandaurov.Fa "char *errbuf" 156c66ca772SSergey Kandaurov.Fc 157*50d3c725SKonstantin Belousov.Ft "struct advlock_list *" 158*50d3c725SKonstantin Belousov.Fo procstat_getadvlock 159*50d3c725SKonstantin Belousov.Fa "struct procstat *procstat" 160*50d3c725SKonstantin Belousov.Fc 1614482b5e3SMikolaj Golub.Ft "char **" 1624482b5e3SMikolaj Golub.Fo procstat_getargv 1634482b5e3SMikolaj Golub.Fa "struct procstat *procstat" 1644482b5e3SMikolaj Golub.Fa "const struct kinfo_proc *kp" 1654482b5e3SMikolaj Golub.Fa "size_t nchr" 1664482b5e3SMikolaj Golub.Fc 1672ff020d3SMikolaj Golub.Ft "Elf_Auxinfo *" 1682ff020d3SMikolaj Golub.Fo procstat_getauxv 1692ff020d3SMikolaj Golub.Fa "struct procstat *procstat" 1702ff020d3SMikolaj Golub.Fa "struct kinfo_proc *kp" 1712ff020d3SMikolaj Golub.Fa "unsigned int *count" 1722ff020d3SMikolaj Golub.Fc 1734482b5e3SMikolaj Golub.Ft "char **" 1744482b5e3SMikolaj Golub.Fo procstat_getenvv 1754482b5e3SMikolaj Golub.Fa "struct procstat *procstat" 1764482b5e3SMikolaj Golub.Fa "const struct kinfo_proc *kp" 1774482b5e3SMikolaj Golub.Fa "size_t nchr" 1784482b5e3SMikolaj Golub.Fc 179c66ca772SSergey Kandaurov.Ft "struct filestat_list *" 180c66ca772SSergey Kandaurov.Fo procstat_getfiles 181c66ca772SSergey Kandaurov.Fa "struct procstat *procstat" 182c66ca772SSergey Kandaurov.Fa "struct kinfo_proc *kp" 183c66ca772SSergey Kandaurov.Fa "int mmapped" 184c66ca772SSergey Kandaurov.Fc 1857f1d14e6SMikolaj Golub.Ft "gid_t *" 1867f1d14e6SMikolaj Golub.Fo procstat_getgroups 1877f1d14e6SMikolaj Golub.Fa "struct procstat *procstat" 1887f1d14e6SMikolaj Golub.Fa "struct kinfo_proc *kp" 1897f1d14e6SMikolaj Golub.Fa "unsigned int *count" 19020ed2b43SJoel Dahl.Fc 19189358231SMikolaj Golub.Ft "struct kinfo_kstack *" 19289358231SMikolaj Golub.Fo procstat_getkstack 19389358231SMikolaj Golub.Fa "struct procstat *procstat" 19489358231SMikolaj Golub.Fa "struct kinfo_proc *kp" 19589358231SMikolaj Golub.Fa "unsigned int *count" 19689358231SMikolaj Golub.Fc 19704017fc7SAllan Jude.Ft int 19804017fc7SAllan Jude.Fo procstat_getosrel 199c66ca772SSergey Kandaurov.Fa "struct procstat *procstat" 20004017fc7SAllan Jude.Fa "struct kinfo_proc *kp" 20104017fc7SAllan Jude.Fa "int *osrelp" 202c66ca772SSergey Kandaurov.Fc 2035b9bcba9SMikolaj Golub.Ft "int" 2044cdf9796SMikolaj Golub.Fo procstat_getpathname 2054cdf9796SMikolaj Golub.Fa "struct procstat *procstat" 2064cdf9796SMikolaj Golub.Fa "struct kinfo_proc *kp" 2074cdf9796SMikolaj Golub.Fa "char *pathname" 2084cdf9796SMikolaj Golub.Fa "size_t maxlen" 2094cdf9796SMikolaj Golub.Fc 21004017fc7SAllan Jude.Ft "struct kinfo_proc *" 21104017fc7SAllan Jude.Fo procstat_getprocs 21204017fc7SAllan Jude.Fa "struct procstat *procstat" 21304017fc7SAllan Jude.Fa "int what" 21404017fc7SAllan Jude.Fa "int arg" 21504017fc7SAllan Jude.Fa "unsigned int *count" 21604017fc7SAllan Jude.Fc 217c45beed8SEnji Cooper.Ft "struct ptrace_lwpinfo *" 218c45beed8SEnji Cooper.Fo procstat_getptlwpinfo 219c45beed8SEnji Cooper.Fa "struct procstat *procstat" 220c45beed8SEnji Cooper.Fa "unsigned int *count" 221c45beed8SEnji Cooper.Fc 2224cdf9796SMikolaj Golub.Ft "int" 2237cc0ebfdSMikolaj Golub.Fo procstat_getrlimit 2247cc0ebfdSMikolaj Golub.Fa "struct procstat *procstat" 2257cc0ebfdSMikolaj Golub.Fa "struct kinfo_proc *kp" 2267cc0ebfdSMikolaj Golub.Fa "int which" 2277cc0ebfdSMikolaj Golub.Fa "struct rlimit* rlimit" 2287cc0ebfdSMikolaj Golub.Fc 2297cc0ebfdSMikolaj Golub.Ft "int" 2305b9bcba9SMikolaj Golub.Fo procstat_getumask 2315b9bcba9SMikolaj Golub.Fa "struct procstat *procstat" 2325b9bcba9SMikolaj Golub.Fa "struct kinfo_proc *kp" 2335b9bcba9SMikolaj Golub.Fa "unsigned short *maskp" 2345b9bcba9SMikolaj Golub.Fc 23539680c7bSMikolaj Golub.Ft "struct kinfo_vmentry *" 23639680c7bSMikolaj Golub.Fo procstat_getvmmap 23739680c7bSMikolaj Golub.Fa "struct procstat *procstat" 23839680c7bSMikolaj Golub.Fa "struct kinfo_proc *kp" 23939680c7bSMikolaj Golub.Fa "unsigned int *count" 24039680c7bSMikolaj Golub.Fc 241c66ca772SSergey Kandaurov.Ft "struct procstat *" 2427153ad2bSMikolaj Golub.Fn procstat_open_core "const char *filename" 2437153ad2bSMikolaj Golub.Ft "struct procstat *" 244c66ca772SSergey Kandaurov.Fn procstat_open_kvm "const char *nlistf" "const char *memf" 245c66ca772SSergey Kandaurov.Ft "struct procstat *" 246c66ca772SSergey Kandaurov.Fn procstat_open_sysctl void 247c66ca772SSergey Kandaurov.Sh DESCRIPTION 248c66ca772SSergey KandaurovThe 249c66ca772SSergey Kandaurov.Nm libprocstat 250c66ca772SSergey Kandaurovlibrary contains the API for runtime file and process information 251c66ca772SSergey Kandaurovretrieval from the running kernel via the 252c66ca772SSergey Kandaurov.Xr sysctl 3 253c66ca772SSergey Kandaurovlibrary backend, and for post-mortem analysis via the 254c66ca772SSergey Kandaurov.Xr kvm 3 2557153ad2bSMikolaj Golublibrary backend, or from the process 2567153ad2bSMikolaj Golub.Xr core 5 2577153ad2bSMikolaj Golubfile, searching for statistics in special 2587153ad2bSMikolaj Golub.Xr elf 3 2597153ad2bSMikolaj Golubnote sections. 260c66ca772SSergey Kandaurov.Pp 261c66ca772SSergey KandaurovThe 262c66ca772SSergey Kandaurov.Fn procstat_open_kvm 263c66ca772SSergey Kandaurovand 264c66ca772SSergey Kandaurov.Fn procstat_open_sysctl 265c66ca772SSergey Kandaurovfunctions use the 266c66ca772SSergey Kandaurov.Xr kvm 3 267c66ca772SSergey Kandaurovor 268c66ca772SSergey Kandaurov.Xr sysctl 3 269c66ca772SSergey Kandaurovlibrary routines, respectively, to access kernel state information 270c66ca772SSergey Kandaurovused to retrieve processes and files states. 271c66ca772SSergey KandaurovThe 2727153ad2bSMikolaj Golub.Fn procstat_open_core 2737153ad2bSMikolaj Golubuses 2747153ad2bSMikolaj Golub.Xr elf 3 2757153ad2bSMikolaj Golubroutines to access statistics stored as a set of notes in a process 2767153ad2bSMikolaj Golub.Xr core 5 2777153ad2bSMikolaj Golubfile, written by the kernel at the moment of the process abnormal termination. 2787153ad2bSMikolaj GolubThe 2797153ad2bSMikolaj Golub.Fa filename 2807153ad2bSMikolaj Golubargument is the process core file name. 2817153ad2bSMikolaj GolubThe 282c66ca772SSergey Kandaurov.Fa nlistf 283c66ca772SSergey Kandaurovargument is the executable image of the kernel being examined. 284c66ca772SSergey KandaurovIf this argument is 285c66ca772SSergey Kandaurov.Dv NULL , 286c66ca772SSergey Kandaurovthe currently running kernel is assumed. 287c66ca772SSergey KandaurovThe 288c66ca772SSergey Kandaurov.Fa memf 289c66ca772SSergey Kandaurovargument is the kernel memory device file. 290c66ca772SSergey KandaurovIf this argument is 291c66ca772SSergey Kandaurov.Dv NULL , 292c66ca772SSergey Kandaurovthen 293c66ca772SSergey Kandaurov.Pa /dev/mem 294c66ca772SSergey Kandaurovis assumed. 295c66ca772SSergey KandaurovSee 296c66ca772SSergey Kandaurov.Xr kvm_open 3 297c66ca772SSergey Kandaurovfor more details. 2987153ad2bSMikolaj GolubThe functions dynamically allocate and return a 299c66ca772SSergey Kandaurov.Vt procstat 300c66ca772SSergey Kandaurovstructure pointer used in the rest of the 301c66ca772SSergey Kandaurov.Nm libprocstat 302c66ca772SSergey Kandaurovlibrary routines until the corresponding 303c66ca772SSergey Kandaurov.Fn procstat_close 304c66ca772SSergey Kandaurovcall that cleans up the resources allocated by the 305c66ca772SSergey Kandaurov.Fn procstat_open_* 306c66ca772SSergey Kandaurovfunctions. 307c66ca772SSergey Kandaurov.Pp 308c66ca772SSergey KandaurovThe 309c66ca772SSergey Kandaurov.Fn procstat_getprocs 310c66ca772SSergey Kandaurovfunction gets a pointer to the 311c66ca772SSergey Kandaurov.Vt procstat 312c66ca772SSergey Kandaurovstructure from one of the 313c66ca772SSergey Kandaurov.Fn procstat_open_* 314c66ca772SSergey Kandaurovfunctions and returns a dynamically allocated (sub-)set of active processes 315c66ca772SSergey Kandaurovin the kernel filled in to array of 316c66ca772SSergey Kandaurov.Vt kinfo_proc 317c66ca772SSergey Kandaurovstructures. 318c66ca772SSergey KandaurovThe 319c66ca772SSergey Kandaurov.Fa what 320c66ca772SSergey Kandaurovand 321c66ca772SSergey Kandaurov.Fa arg 322c66ca772SSergey Kandaurovarguments constitute a filtering predicate as described in the 323c66ca772SSergey Kandaurov.Xr kvm_getprocs 3 324c66ca772SSergey Kandaurovfunction. 325c66ca772SSergey KandaurovThe number of processes found is returned in the reference parameter 326c66ca772SSergey Kandaurov.Fa cnt . 327c66ca772SSergey KandaurovThe caller is responsible to free the allocated memory with a subsequent 328c66ca772SSergey Kandaurov.Fn procstat_freeprocs 329c66ca772SSergey Kandaurovfunction call. 330c66ca772SSergey Kandaurov.Pp 331c66ca772SSergey KandaurovThe 332c45beed8SEnji Cooper.Fn procstat_getptlwpinfo 333c45beed8SEnji Cooperfunction gets a pointer to the 334c45beed8SEnji Cooper.Vt procstat 335c45beed8SEnji Cooperstructure from the 336c45beed8SEnji Cooper.Fn procstat_open_core 337c45beed8SEnji Cooperfunction and returns a dynamically allocated set of signals intercepted by a 338c45beed8SEnji Cooperprocess in the process's core file. 339c45beed8SEnji CooperThe number of processes found is returned in the reference parameter 340c45beed8SEnji Cooper.Fa cnt . 341c45beed8SEnji CooperThe caller is responsible to free the allocated memory with a subsequent 342c45beed8SEnji Cooper.Fn procstat_freeptlwpinfo 343c45beed8SEnji Cooperfunction call. 344c45beed8SEnji Cooper.Pp 345c45beed8SEnji CooperThe 3464482b5e3SMikolaj Golub.Fn procstat_getargv 3474482b5e3SMikolaj Golubfunction gets a pointer to the 3484482b5e3SMikolaj Golub.Vt procstat 3494482b5e3SMikolaj Golubstructure from one of the 3504482b5e3SMikolaj Golub.Fn procstat_open_* 3514482b5e3SMikolaj Golubfunctions, a pointer to 3524482b5e3SMikolaj Golub.Vt kinfo_proc 3534482b5e3SMikolaj Golubstructure from the array obtained from the 35416e1abe4SMateusz Piotrowski.Fn procstat_getprocs 3554482b5e3SMikolaj Golubfunction, and returns a null-terminated argument vector that corresponds to 3564482b5e3SMikolaj Golubthe command line arguments passed to the process. 3574482b5e3SMikolaj GolubThe 3584482b5e3SMikolaj Golub.Fa nchr 3594482b5e3SMikolaj Golubargument indicates the maximum number of characters, including null bytes, 3604482b5e3SMikolaj Golubto use in building the strings. 3614482b5e3SMikolaj GolubIf this amount is exceeded, the string causing the overflow is truncated and 3624482b5e3SMikolaj Golubthe partial result is returned. 3634482b5e3SMikolaj GolubThis is handy for programs that print only a one line summary of a 3644482b5e3SMikolaj Golubcommand and should not copy out large amounts of text only to ignore it. 3654482b5e3SMikolaj GolubIf 3664482b5e3SMikolaj Golub.Fa nchr 3674482b5e3SMikolaj Golubis zero, no limit is imposed and all argument strings are returned. 3684482b5e3SMikolaj GolubThe values of the returned argument vector refer the strings stored 3694482b5e3SMikolaj Golubin the 3704482b5e3SMikolaj Golub.Vt procstat 3714482b5e3SMikolaj Golubinternal buffer. 3724482b5e3SMikolaj GolubA subsequent call of the function with the same 3734482b5e3SMikolaj Golub.Vt procstat 3744482b5e3SMikolaj Golubargument will reuse the buffer. 3754482b5e3SMikolaj GolubTo free the allocated memory 3764482b5e3SMikolaj Golub.Fn procstat_freeargv 3774482b5e3SMikolaj Golubfunction call can be used, or it will be released on 3784482b5e3SMikolaj Golub.Fn procstat_close . 3794482b5e3SMikolaj Golub.Pp 3804482b5e3SMikolaj GolubThe 3814482b5e3SMikolaj Golub.Fn procstat_getenvv 3824482b5e3SMikolaj Golubfunction is similar to 3834482b5e3SMikolaj Golub.Fn procstat_getargv 3844482b5e3SMikolaj Golubbut returns the vector of environment strings. 3854482b5e3SMikolaj GolubThe caller may free the allocated memory with a subsequent 38645805bd7SEnji Cooper.Fn procstat_freeenvv 3874482b5e3SMikolaj Golubfunction call. 3884482b5e3SMikolaj Golub.Pp 3894482b5e3SMikolaj GolubThe 3902ff020d3SMikolaj Golub.Fn procstat_getauxv 3912ff020d3SMikolaj Golubfunction gets a pointer to the 3922ff020d3SMikolaj Golub.Vt procstat 3932ff020d3SMikolaj Golubstructure, a pointer to 3942ff020d3SMikolaj Golub.Vt kinfo_proc 3952ff020d3SMikolaj Golubstructure, and returns the auxiliary vector as a dynamically allocated array of 3962ff020d3SMikolaj Golub.Vt Elf_Auxinfo 3972ff020d3SMikolaj Golubelements. 3982ff020d3SMikolaj GolubThe caller is responsible to free the allocated memory with a subsequent 3992ff020d3SMikolaj Golub.Fn procstat_freeauxv 4002ff020d3SMikolaj Golubfunction call. 4012ff020d3SMikolaj Golub.Pp 4022ff020d3SMikolaj GolubThe 403c66ca772SSergey Kandaurov.Fn procstat_getfiles 404c66ca772SSergey Kandaurovfunction gets a pointer to the 405c66ca772SSergey Kandaurov.Vt procstat 406c66ca772SSergey Kandaurovstructure initialized with one of the 407c66ca772SSergey Kandaurov.Fn procstat_open_* 408c66ca772SSergey Kandaurovfunctions, a pointer to 409c66ca772SSergey Kandaurov.Vt kinfo_proc 410c66ca772SSergey Kandaurovstructure from the array obtained from the 41116e1abe4SMateusz Piotrowski.Fn procstat_getprocs 412c66ca772SSergey Kandaurovfunction, and returns a dynamically allocated linked list of filled in 413c66ca772SSergey Kandaurov.Vt filestat_list 414c66ca772SSergey Kandaurovstructures using the STAILQ macros defined in 415c66ca772SSergey Kandaurov.Xr queue 3 . 416c66ca772SSergey KandaurovThe caller is responsible to free the allocated memory with a subsequent 417c66ca772SSergey Kandaurov.Fn procstat_freefiles 418c66ca772SSergey Kandaurovfunction call. 419c66ca772SSergey Kandaurov.Pp 420c66ca772SSergey KandaurovThe 4217f1d14e6SMikolaj Golub.Fn procstat_getgroups 4227f1d14e6SMikolaj Golubfunction gets a pointer to the 4237f1d14e6SMikolaj Golub.Vt procstat 4247f1d14e6SMikolaj Golubstructure, a pointer to 4257f1d14e6SMikolaj Golub.Vt kinfo_proc 4267f1d14e6SMikolaj Golubstructure, and returns the process groups as a dynamically allocated array of 4277f1d14e6SMikolaj Golub.Vt gid_t 4287f1d14e6SMikolaj Golubelements. 4297f1d14e6SMikolaj GolubThe caller is responsible to free the allocated memory with a subsequent 4307f1d14e6SMikolaj Golub.Fn procstat_freegroups 4317f1d14e6SMikolaj Golubfunction call. 4327f1d14e6SMikolaj Golub.Pp 4337f1d14e6SMikolaj GolubThe 43489358231SMikolaj Golub.Fn procstat_getkstack 43589358231SMikolaj Golubfunction gets a pointer to the 43689358231SMikolaj Golub.Vt procstat 43789358231SMikolaj Golubstructure initialized with one of the 43889358231SMikolaj Golub.Fn procstat_open_* 43989358231SMikolaj Golubfunctions, a pointer to 44089358231SMikolaj Golub.Vt kinfo_proc 44189358231SMikolaj Golubstructure, and returns kernel stacks of the process as a dynamically allocated 44289358231SMikolaj Golubarray of 44389358231SMikolaj Golub.Vt kinfo_kstack 44489358231SMikolaj Golubstructures. 44589358231SMikolaj GolubThe caller is responsible to free the allocated memory with a subsequent 44689358231SMikolaj Golub.Fn procstat_freekstack 44789358231SMikolaj Golubfunction call. 44889358231SMikolaj Golub.Pp 44989358231SMikolaj GolubThe 450eec6cb1cSMikolaj Golub.Fn procstat_getosrel 451eec6cb1cSMikolaj Golubfunction gets a pointer to the 452eec6cb1cSMikolaj Golub.Vt procstat 453eec6cb1cSMikolaj Golubstructure, a pointer to 454eec6cb1cSMikolaj Golub.Vt kinfo_proc 455eec6cb1cSMikolaj Golubstructure, and returns osrel date in the 3rd reference parameter. 456eec6cb1cSMikolaj Golub.Pp 457eec6cb1cSMikolaj GolubThe 4584cdf9796SMikolaj Golub.Fn procstat_getpathname 4594cdf9796SMikolaj Golubfunction gets a pointer to the 4604cdf9796SMikolaj Golub.Vt procstat 4614cdf9796SMikolaj Golubstructure, a pointer to 4624cdf9796SMikolaj Golub.Vt kinfo_proc 4634cdf9796SMikolaj Golubstructure, and copies the path of the process executable to 4644cdf9796SMikolaj Golub.Fa pathname 4654cdf9796SMikolaj Golubbuffer, limiting to 4664cdf9796SMikolaj Golub.Fa maxlen 4674cdf9796SMikolaj Golubcharacters. 4684cdf9796SMikolaj Golub.Pp 4694cdf9796SMikolaj GolubThe 4707cc0ebfdSMikolaj Golub.Fn procstat_getrlimit 4717cc0ebfdSMikolaj Golubfunction gets a pointer to the 4727cc0ebfdSMikolaj Golub.Vt procstat 4737cc0ebfdSMikolaj Golubstructure, a pointer to 4747cc0ebfdSMikolaj Golub.Vt kinfo_proc 4757cc0ebfdSMikolaj Golubstructure, resource index 4767cc0ebfdSMikolaj Golub.Fa which , 4777cc0ebfdSMikolaj Goluband returns the actual resource limit in the 4th reference parameter. 4787cc0ebfdSMikolaj Golub.Pp 4797cc0ebfdSMikolaj GolubThe 4805b9bcba9SMikolaj Golub.Fn procstat_getumask 4815b9bcba9SMikolaj Golubfunction gets a pointer to the 4825b9bcba9SMikolaj Golub.Vt procstat 4835b9bcba9SMikolaj Golubstructure, a pointer to 4845b9bcba9SMikolaj Golub.Vt kinfo_proc 4855b9bcba9SMikolaj Golubstructure, and returns the process umask in the 3rd reference parameter. 4865b9bcba9SMikolaj Golub.Pp 4875b9bcba9SMikolaj GolubThe 48839680c7bSMikolaj Golub.Fn procstat_getvmmap 48939680c7bSMikolaj Golubfunction gets a pointer to the 49039680c7bSMikolaj Golub.Vt procstat 49139680c7bSMikolaj Golubstructure initialized with one of the 49239680c7bSMikolaj Golub.Fn procstat_open_* 49339680c7bSMikolaj Golubfunctions, a pointer to 49439680c7bSMikolaj Golub.Vt kinfo_proc 49539680c7bSMikolaj Golubstructure, and returns VM layout of the process as a dynamically allocated 49639680c7bSMikolaj Golubarray of 49739680c7bSMikolaj Golub.Vt kinfo_vmentry 49839680c7bSMikolaj Golubstructures. 49939680c7bSMikolaj GolubThe caller is responsible to free the allocated memory with a subsequent 50039680c7bSMikolaj Golub.Fn procstat_freevmmap 50139680c7bSMikolaj Golubfunction call. 50239680c7bSMikolaj Golub.Pp 50339680c7bSMikolaj GolubThe 504*50d3c725SKonstantin Belousov.Fn procstat_getadvlock 505*50d3c725SKonstantin Belousovfunction returns a dynamically allocated list of 506*50d3c725SKonstantin Belousov.Va struct advlock 507*50d3c725SKonstantin Belousovstructures, providing a snapshot of the currently 508*50d3c725SKonstantin Belousovacquired advisory locks in the system. 509*50d3c725SKonstantin BelousovBoth locally acquired POSIX ( 510*50d3c725SKonstantin Belousov.Xr fcntl 2 ) 511*50d3c725SKonstantin Belousovand BSD-style ( 512*50d3c725SKonstantin Belousov.Xr flock 2 ) 513*50d3c725SKonstantin Belousovlocks are reported, as well as locks established by remote file 514*50d3c725SKonstantin Belousovsystem protocols. 515*50d3c725SKonstantin BelousovFor each lock, unique identifiers for the locked file and its mount point 516*50d3c725SKonstantin Belousovare guaranteed to be provided. 517*50d3c725SKonstantin BelousovIf a path for the locked file can be reconstructed, it is provided as well. 518*50d3c725SKonstantin BelousovThe returned list must be freed with the 519*50d3c725SKonstantin Belousov.Fn procstat_freeadvlock 520*50d3c725SKonstantin Belousovfunction. 521*50d3c725SKonstantin Belousov.Pp 522*50d3c725SKonstantin BelousovThe 523c66ca772SSergey Kandaurov.Fn procstat_get_pipe_info , 524c66ca772SSergey Kandaurov.Fn procstat_get_pts_info , 525958aa575SJohn Baldwin.Fn procstat_get_sem_info , 526e506e182SJohn Baldwin.Fn procstat_get_shm_info , 527c66ca772SSergey Kandaurov.Fn procstat_get_socket_info 528c66ca772SSergey Kandaurovand 529c66ca772SSergey Kandaurov.Fn procstat_get_vnode_info 530a3fb6da9SGlen Barberfunctions are used to retrieve information about pipes, pseudo-terminals, 531958aa575SJohn Baldwinsemaphores, shared memory objects, 532c66ca772SSergey Kandaurovsockets, and vnodes, respectively. 533c66ca772SSergey KandaurovEach of them have a similar interface API. 534c66ca772SSergey KandaurovThe 535c66ca772SSergey Kandaurov.Fa procstat 536c66ca772SSergey Kandaurovargument is a pointer obtained from one of 537c66ca772SSergey Kandaurov.Fn procstat_open_* 538c66ca772SSergey Kandaurovfunctions. 539c66ca772SSergey KandaurovThe 540c66ca772SSergey Kandaurov.Ft filestat Fa fst 541c66ca772SSergey Kandaurovargument is an element of STAILQ linked list as obtained from the 542c66ca772SSergey Kandaurov.Fn procstat_getfiles 543c66ca772SSergey Kandaurovfunction. 544c66ca772SSergey KandaurovThe 545c66ca772SSergey Kandaurov.Ft filestat 546c66ca772SSergey Kandaurovstructure contains a 547c66ca772SSergey Kandaurov.Fa fs_type 548c66ca772SSergey Kandaurovfield that specifies a file type and a corresponding function to be 549c66ca772SSergey Kandaurovcalled among the 550c66ca772SSergey Kandaurov.Nm procstat_get_*_info 551c66ca772SSergey Kandaurovfunction family. 552c66ca772SSergey KandaurovThe actual object is returned in the 3rd reference parameter. 553c66ca772SSergey KandaurovThe 554c66ca772SSergey Kandaurov.Fa errbuf 555c66ca772SSergey Kandaurovargument indicates an actual error message in case of failure. 556c66ca772SSergey Kandaurov.Pp 557c66ca772SSergey Kandaurov.Bl -tag -width 20n -compact -offset indent 558c66ca772SSergey Kandaurov.It Li PS_FST_TYPE_FIFO 559c66ca772SSergey Kandaurov.Nm procstat_get_vnode_info 560c66ca772SSergey Kandaurov.It Li PS_FST_TYPE_VNODE 561c66ca772SSergey Kandaurov.Nm procstat_get_vnode_info 562c66ca772SSergey Kandaurov.It Li PS_FST_TYPE_SOCKET 563c66ca772SSergey Kandaurov.Nm procstat_get_socket_info 564c66ca772SSergey Kandaurov.It Li PS_FST_TYPE_PIPE 565c66ca772SSergey Kandaurov.Nm procstat_get_pipe_info 566c66ca772SSergey Kandaurov.It Li PS_FST_TYPE_PTS 567c66ca772SSergey Kandaurov.Nm procstat_get_pts_info 568958aa575SJohn Baldwin.It Li PS_FST_TYPE_SEM 569958aa575SJohn Baldwin.Nm procstat_get_sem_info 570e506e182SJohn Baldwin.It Li PS_FST_TYPE_SHM 571e506e182SJohn Baldwin.Nm procstat_get_shm_info 572c66ca772SSergey Kandaurov.El 573c66ca772SSergey Kandaurov.Sh SEE ALSO 574c66ca772SSergey Kandaurov.Xr fstat 1 , 575c66ca772SSergey Kandaurov.Xr fuser 1 , 576c66ca772SSergey Kandaurov.Xr pipe 2 , 577e506e182SJohn Baldwin.Xr shm_open 2 , 578c66ca772SSergey Kandaurov.Xr socket 2 , 5797153ad2bSMikolaj Golub.Xr elf 3 , 580c66ca772SSergey Kandaurov.Xr kvm 3 , 581c66ca772SSergey Kandaurov.Xr queue 3 , 582958aa575SJohn Baldwin.Xr sem_open 3 , 583c66ca772SSergey Kandaurov.Xr sysctl 3 , 584c66ca772SSergey Kandaurov.Xr pts 4 , 5857153ad2bSMikolaj Golub.Xr core 5 , 586c66ca772SSergey Kandaurov.Xr vnode 9 587c66ca772SSergey Kandaurov.Sh HISTORY 588c66ca772SSergey KandaurovThe 589c66ca772SSergey Kandaurov.Nm libprocstat 590c66ca772SSergey Kandaurovlibrary appeared in 591c66ca772SSergey Kandaurov.Fx 9.0 . 592c66ca772SSergey Kandaurov.Sh AUTHORS 593813f118cSSergey Kandaurov.An -nosplit 594813f118cSSergey KandaurovThe 595813f118cSSergey Kandaurov.Nm libprocstat 596813f118cSSergey Kandaurovlibrary was written by 5972b7af31cSBaptiste Daroussin.An Stanislav Sedov Aq Mt [email protected] . 598813f118cSSergey Kandaurov.Pp 599813f118cSSergey KandaurovThis manual page was written by 6002b7af31cSBaptiste Daroussin.An Sergey Kandaurov Aq Mt [email protected] . 601